How can I initialize an index giving its size thru an int variable aiming the something like the above:
int x=10;
char test[x];
Thank you,
Thiago Santana
How can I initialize an index giving its size thru an int variable aiming the something like the above:
int x=10;
char test[x];
Thank you,
Thiago Santana
Thanks Elysia,
But quite not what I am looking for. I just want to inform the simple array size being the size an int variable. It has to be a very simple array like the one I have sample on my original post.
Thank you,
Thiago Santana
You can't do that legally with a variable. If you know x will be 10 (or some other number) when you write the program use this:Some compilers allow your original code as an extension, but as I said that's not strictly legal in C++.Code:const int x=10; char test[x];
If the size is not a constant (and you want to use standard C++), then you have no choice but to use a dynamic array container. The best choice for that is vector (or string) as shown by Elysia. You can also use new[]/delete[], but that would make sense only if your instructor doesn't allow you to use vector for some reason.
Thanks Daved and Elysa for the inputs. That helps me.