I have a program which reads an input integer and uses this integer to determine the length of an integer array.
My question is, how the program knows how much memory to reserve in Stack. My understanding is arrays are stored in stack. The process is fairly a compile time task. But how the compiler knows how much space needs to be reserved in stack.
Following is the program,
#include<stdio.h>
int main() {
int n;
scanf("%d", &n);
int arr[n];
for(int c=0; c<=n;c++){
arr[c]=0;
}
for(int c=0; c<=n;c++){
printf("%d\n", arr[c]);
}
}