Home > Back-end > Temporary variables within the function into the parameter as a function of the array length is what
Temporary variables within the function into the parameter as a function of the array length is what
Time:09-30
Func (int len... ) { An int array (len)={0}; } Because of the participation and the array itself are saved on the stack, so the redistribution when the array length have been confirmed in len, so there will be no problem, is it
If memory function need recommend wrote above, or below wrote
Array length must be a compile time can be determined, Unless it is support variable-length array compiler,
CodePudding user response:
The first is problematic, because len uncertain length, so the compiler doesn't know for how long array, it apply for The second is no problem, because is a dynamic application, is in the calling function to malloc application space,
CodePudding user response:
First there is a problem, syntax error Or Array [len]=10; Or An int array [100]={10};
Int array (len)={10} not write so much
CodePudding user response:
C99 has a vla features to support you with variable as the array size
CodePudding user response:
But the VLA cannot initialize The first piece of code so you should still wrong
CodePudding user response:
This to is not saved on the stack, starting from the C99 introduced VLA, so an int array (len) legal, but cannot use {} initialization, the first piece of code can be compiled through, shows that the compiler is a c + +, and not the kind of archaic times ~ ~ ~