Thread: What's wrong with this code...?

  1. #1
    C++ SharK The SharK's Avatar
    Join Date
    Mar 2004
    Location
    Denmark
    Posts
    62

    Question What's wrong with this code...?

    There's something wrong with the line:
    Code:
    int myArray[4] = (1, 2, 3, 4);
    Code:
    #include "stdafx.h"
    #include <iostream>
    
    using namespace std;
    
    int main()
    
    {
    	int myArray[4] = (1, 2, 3, 4);
    
    	cout << (int)myArray << endl;
    
    	return 0;
    }

    regards,

    The SharK
    Studying programming languages,
    you'll ALWAYS be a student ;-)

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Look up the format for an initializer list for an array. You're close, but with C++ it's all in the details.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Also, (int) is an old C-style cast. Use C++ casts.

  4. #4
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200
    Use this:
    Code:
    int myArray[4] = {1, 2, 3, 4};
    The braces are for the array not these '( )'
    Hello, testing testing. Everthing is running perfectly...for now

  5. #5
    C++ SharK The SharK's Avatar
    Join Date
    Mar 2004
    Location
    Denmark
    Posts
    62
    I see, now it works

    thanks


    The SharK
    Studying programming languages,
    you'll ALWAYS be a student ;-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is wrong in this simple code
    By vikingcarioca in forum C Programming
    Replies: 4
    Last Post: 04-23-2009, 07:10 AM
  2. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 10:11 AM
  3. I cant find what is wrong with this code
    By senegene in forum C Programming
    Replies: 1
    Last Post: 11-12-2002, 06:32 PM
  4. Anyone see what is wrong with this code?
    By Wise1 in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 02:01 PM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 12:51 AM