S
Sunny
#include <iostream>
int main()
{
int len;
std::cin >> len;
int Arr[len];
int *p = new int[len];
Arr[len-1]=5;
std::cout << &len << " " << &Arr << " " << p << std::endl;
return 0;
}
This code declares an array Arr of size len which is not fixed at
compile time. This program compiles using g++ (gcc version 3.2.3
20030502) and works properly. I am surprised to see this because I
thought arrays in C++ should have size fixed at compile time.
Is g++ deviating from standards here?
int main()
{
int len;
std::cin >> len;
int Arr[len];
int *p = new int[len];
Arr[len-1]=5;
std::cout << &len << " " << &Arr << " " << p << std::endl;
return 0;
}
This code declares an array Arr of size len which is not fixed at
compile time. This program compiles using g++ (gcc version 3.2.3
20030502) and works properly. I am surprised to see this because I
thought arrays in C++ should have size fixed at compile time.
Is g++ deviating from standards here?