I read that while dynamic memory is allocated on the heap during runtime, static memory is allocated on the stack during compile time since the compiler knows how much memory has to be allocated at compile time.
Consider the following code:
int n;
cin>>n;
int a[n];
How does the compiler possibly know how much memory to allocate for a[] at compile time if its actual size is read during the run only?