declare array once C -
if have function called lot of times, , function needs array of 16 pointers updated new pointers every time it's called, right way declare array?
char** readuserinput() { static char* cmds[16]; ... }
will array initialized once?
yes, static variables initialized once. declaring variable cmds
declaring array of 16 char*
s. array initialized zeroes. array never initialized again.
take code example:
int i; static char *cmds[5]; (i = 0;i<5;++i) { printf("%d ", cmds[i]); }
it prints:
0 0 0 0 0
Comments
Post a Comment