Thread: Two Dimensional Array Passing

  1. #16
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    Tell me to go back to the C board if you want but is this legal in C++?
    Almost. It is legal, but it should not compile because nothing has been initialized.
    Last edited by Enahs; 09-20-2005 at 09:44 PM.

  2. #17
    Registered User
    Join Date
    Sep 2005
    Posts
    85
    This Works Great....thank You For All Of Your Help. If Ever In The Nw Pa Area Maybe I Can Take You For A Plane Ride....as I Am A Pilot Too.

  3. #18
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Quote Originally Posted by sand_man
    Tell me to go back to the C board if you want but is this legal in C++?
    Code:
    int main(){
      int x = 5;
      int arr[x];
      return 0;
    }
    I don't think so. I think x should be constant. Someone please correct me if I'm wrong, but I believe the standard way to dynamically allocate an array is:
    Code:
    int x = 5;
    int* arr = new int[x];
    Edit:
    And VS 2003 won't compile it:
    error C2057: expected constant expression
    error C2466: cannot allocate an array of constant size 0
    error C2133: 'array' : unknown size
    Last edited by JaWiB; 09-20-2005 at 11:17 PM.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #19
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by JaWiB
    And VS 2003 won't compile it:
    I move we create a seperate topic when referring to what VS doesnt like and put it in its own forum.. because VS's a loner.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help passing nxn array to 2d array.
    By beglaryanh in forum C Programming
    Replies: 2
    Last Post: 06-06-2009, 05:23 PM
  2. Zero out two dimensional array
    By davo666 in forum C Programming
    Replies: 16
    Last Post: 01-08-2009, 05:28 AM
  3. Multi dimensional array
    By $l4xklynx in forum C Programming
    Replies: 7
    Last Post: 01-03-2009, 03:56 AM
  4. Replies: 5
    Last Post: 11-20-2001, 12:48 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM