Q:

Why does array allocation with a variable work?

This code:
int main() {
   int size;
   scanf("%d", &size);
   int array[size]; 
}

works fine with GCC, but VC expects a constant expression for the size of the array so does not compile it (which makes more sense to me). Any idea why it works with GCC?

A:

Yes, because gcc supports variable length arrays.
It was added as a part of C99 standard, however, in the later standards (C11 and C18), it's an optional feature.

