array

char test[1000][1000]

can I write this :
char test[n][1000]

so i can define n later?

thanks
Firstly, many C++ compilers will rightfully object to this, as variable arrays are non-standard. Some will let you do it under various circumstances.

so i can define n later?


Do you mean later in the code, or do you mean it will be earlier in the code, but you will write that bit later.

If you mean later in the code, what you're asking is silly. At the point of dealing with char test[n][1000], even if your compiler doesn't rightfully object to a non-constant size array, n will have some value. If you've not set a value, it will be some garbage value. Changing the value of n later will make no difference.

If you mean earlier in the code, it depends on your compiler. Some will not let you do it, some will let you do it so long as n is a const, some will happily let you do it even if n is not const.

The C++ way to deal with this sort of thing is to use a proper container such as Vector
Last edited on
Topic archived. No new replies allowed.