I was experimenting with clang (10.0) on win 10, with the following snippet:
#include <iostream>
using namespace std;
int main()
{
const int N = 10;
int ii;
cout << "Enter value for ii: ";
cin >> ii;
int a[N+ii];
for (int i = 0; i < N+ii; ++i) {
a[i] = 0;
}
for (int i = 0; i < N+ii; ++i) {
cout << "a[ " << i << "] = " << a[i] << endl;
}
return 0;
}
I am not sure as to Why are there no compilation error (the size of the array a
is unkown at compile time) ????
PS:
- Both
for
loops were meant to trigger segmentation fault. - command to compile:
clang.exe exp.cpp
- I have tried to run the code with large values for
ii
but it seems to work fine (ii = 10000, 100000, 1000000)