According to c++11 standard, Variable length array(VLA) is not allowed using array size declarator (I know that VLA can be created using dynamic memory allocation). Array size declarator must be a constant literal. But when I run the following code with VLA, it executes without any errors. I'm I interpreting the standard wrong or missing something?
#include <iostream>
using namespace std;
void displayArray(int n) {
int arr[n] = {0};
for (int i = 0; i < n; i++) {
cout << arr[i] << endl;
}
}
int main() {
int size;
cin >> size;
displayArray(size);
}
Compiled using: g++ -std=c++11 -o test test.cpp
Any help is appreciated. Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire