Take the 2-minute tour ×  I'm not a C++ expert, but afaik this
code should fail due to size not being constant:   using
namespace std;  int main(int argc, char** argv)   int size =
*argv[1] - 48;   char array [size];    return 0;  Why does this
work when I compile that with gcc(better say g++)?  ./test 7
/test 2   Thanks in advance  share|improve this question add
comment  7 Answers  To allocate memory from stack or heap for a
variable, the size of the variable need to be known. C++
compilers can decide themselves how they allocate memory, but
c++ has made it public how they expect c++ compilers to handle
the situation, and thus c++ std requires that compiler vendors
publish their memory handling. This happens via sizeof operator.
This operator is calculated completely in compile-time. The
compile-time restriction for the array sizes comes from this
requirement.  int arr[10]; std::cout << sizeof(arr) << std::endl
since every variable and type supports sizeof, their sizes need
to be calculated on compile-time