When exactly is stack allocated [duplicate]
问题 This question already has answers here : At what exact moment is a local variable allocated storage? (5 answers) Closed 3 years ago . Even in C (not just C++) you can declare variables at the start of a code block, which is enclosed in curly braces. Example: #include <stdio.h> void use_stack(int cnt) { if (cnt<=16) { int a[16]; int i; a[0]=3; a[1]=5; for (i=2;i<cnt;i++) { a[i]=a[i-1]+a[i-2]; } printf("a[%d] == %d\n",cnt-1,a[cnt-1]); } else { printf("cnt is too big\n"); } } Now I know that