0

EX:

const int SIZE = 10; 
int arr[SIZE]; 

vs

int SIZE = 10; 
int arr[SIZE]; 

Even though the compiler doesn't seem to show any errors in the run time.

Stack Danny
  • 7,754
  • 2
  • 26
  • 55
  • 2
    In c++ array size must be constant expressions. Your second example is non standard c++ and should be avoided. – Hackjaku Sep 14 '22 at 13:23
  • 1
    When compiling use `-pedantic-errors`. Then you will get an error for the second code block. – NathanOliver Sep 14 '22 at 13:24
  • Visual Studio will show you an error if you try to compile the second version. gcc and clang unfortunately allow that by default. – Yksisarvinen Sep 14 '22 at 13:29
  • 1
    "The compiler" is wrong if it accepts that second code example without issuing a diagnostic. That is not valid C++. – Pete Becker Sep 14 '22 at 13:48

0 Answers0