Hi guys,
As I understand that the if the length of the array isn't constant (variable) then in c/c++ I can't declare it and I must create it dynamically.
This point I understand, but what about if I create an array in one function and I pass the length of the array as argument .. will it be allowed in c/c++?
I'll explain by an example:
Code:
void doSomething(int length)
{
int array[length]={0}; // here length isn't run time cosntant, so creation of the array must be dynamically no?
}
int main()
{
int length=9;
doSomething(length);
return 0;
}
I passed the length as argument to function doSomething , and there I create an array, but the variable length is considered variable because it's not a run time constant variable .. so it's not allowed to create the array in this way and I need to create it dynamically . Am I right?
Another question, what about if the length is of type const int length. still I can't create the array and need to dynamically create it?
I need to understand the concept when I need to create dynamically the array if the length is variable - i.e isn't a run time /compile time constant.
THANKS!