People, I think I will throw away all my humble knowledge of C. Look at this code:
int main(int argc, char** argv, char** envp) { int aa; srand(time(NULL)); int Num = rand()%20; int Vetor[Num]; for (aa = 0; aa < Num; aa++) { Vetor[aa] = rand()%40; printf("Vetor [%d] = %d\n", aa, Vetor[aa]); } }
I would think that this should cause an error for two reasons: firstly, I declare Num and Vetor after executing the command (srand), and second, because I declare Vetor based on Num, it should not be right? because these array sizes should not be decided at runtime, but at compile time right?
I am really surprised that his work, and if you guys could explain why I can use such things as that would be great.
This is the use of GCC.
source share