0

When I type:

int n; 
cin >> n; 
int a[n]; 

It works on VS code but doesn't work on Visual Studio.

I expected it not to work at all because of memory-related stuff.

So, any explanation why it does work on VS code ?

mark coder
  • 11
  • 5

1 Answers1

3

a[n] is variable-length array (VLA) which is a C99 feature. It is not a C++ feature. Some C++ compilers, never the less, accept the syntax as a compiler extension.

Allan Wind
  • 23,068
  • 5
  • 28
  • 38
  • 1
    Does the memory allocated for the array in our case belongs to stack or heap? If heap, can a memory leak happens as expected? should I delete it ? – mark coder Feb 27 '21 at 08:19
  • It depends on the compiler. gcc allocates it on the stack and why it's dangerous. You don't need to deallocate it. – Allan Wind Feb 27 '21 at 08:23