I'm working on a small programming exercise in C++. Goal is to initiate an array with the first 32 exponentations of 2 and to output them afterwards. Using a normal for loop there's no problem but I tried to use the range-based for loop introduced in the C++11 standard. During compilation I get the warning "range-based for loop is a C++11 extension [-Wc++11-extensions]". Running the program I get the error "Segmentation fault: 11" without any further output.
I got already that the elem variable somehow is broken but I don't know how. Hope you can help a n00b :)
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
const int LAENGE = 32;
long potenzen[LAENGE];
for(int elem : potenzen)
{
potenzen[elem] = pow(2.0, (double) (elem + 1));
}
for(int elem : potenzen)
{
cout << endl;
cout << potenzen[elem];
}
cout << endl;
return 0;
}