#include <iostream>
using namespace std;
int a[4];
int main(){
int b=7;
cout<<a[b]<<endl;
return 0;
}
I was trying to access the memory that was not allocated. So I expect the output to be a segmentation fault,instead the output is some garbage value.
Later I increased 'b' to 1000, now the output is 'Segmentation fault'. Is there a specific reason for this kind of behaviour?
I'm using gcc-4.3.2 compiler.