-1
void foo (int k)
{

int C[size(k)][size(k)];

C[1][2] = 4;

std::cout << C[1][2];

}

How this code is compiled correctly?

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190

1 Answers1

1

You code compiles with g++ because it supports variable length arrays as an extension; see 6.19 Arrays of Variable Length

It's not a feature of standard C++, so it won't necessarily work with other compilers.

If you want g++ to complain about this sort of thing, give it -pedantic.

RichieHindle
  • 272,464
  • 47
  • 358
  • 399