0
#include<stdio.h>
int main(){
    int n;
    printf("Enter a value for n\n");
    scanf("%d",&n);
    int A[n];
}

Why can't I assign the size of an array explicitly from a user?

1 Answers1

-1

There is VLA support in C99 and C11 (optional). With GCC 7.2.1 your example works. I compiled like this:

gcc abc.c -o abc

gcc --std=c99 abc.c -o abc

Looks like your compiler does not support this feature.

Doncho Gunchev
  • 2,159
  • 15
  • 21
  • 1
    C/C++ is not a language. This is a C question so answers relating to C++ constructs are off topic. Furthermore, C99 supports Variable Length Arrays, and C11 has optional support for VLAs. – Christian Gibbons Oct 25 '17 at 16:44
  • You are correct. C++ does not, C11 does.. will fix the answer shortly... – Doncho Gunchev Oct 25 '17 at 17:03