Little questions about VLA

Revision en1, by xcx0902, 2024-03-20 15:16:42

As we all know, we can write codes like this in C++:

int main() {
    int n;
    cin >> n;
    int a[n];
    ...
}

But when the inputed n is too large, this program will crash.

So,

  1. Why it would crash?
  2. What is the lowest value n to make it crash?
  3. Why using malloc will not cause this problem?
Tags vla

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English xcx0902 2024-03-20 15:16:42 365 Initial revision (published)