Thread: variables in array declarations

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    14

    Question variables in array declarations

    Is it possible to use a variable in an array declaration such as:

    char arr[number][20];

    where number is a number found in an input file.

    If so, I'd appreciate it if you let me know how.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Is it possible to use a variable in an array declaration
    In the C89 standard, no. All array declarations must use an integer constant as the size. This changed with the C99 standard which does allow variables to be used as the size in an array declaration, but very few compilers conform to the new standard at this time.

    In my personal opinion, this new feature is just a convenience that will complicate the language even more and was added for the benefit of novices since experienced programmers are familiar with getting around the restriction with relative ease.

    So the answer to your question is no and yes depending on whether or not your compiler is C99 compliant

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 1-D array
    By jack999 in forum C++ Programming
    Replies: 24
    Last Post: 05-12-2006, 07:01 PM
  2. 2d array question
    By gmanUK in forum C Programming
    Replies: 2
    Last Post: 04-21-2006, 12:20 PM
  3. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  4. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM
  5. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 04:27 PM