The following source code compiles and runs fine
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int t;
cout << t << endl; // the seg fault / rte is for this
cout << t+10 << endl;
int mat[0];
int mat2[t+10];
for (int i = 0 ; i<100 ; i++) {
//cout << mat[i] << endl;
}
cout << sizeof(mat)/sizeof(int) << endl;
cout << sizeof(mat2)/sizeof(int) << endl;
//cin >> t;
return 0;
}
But if I uncomment the cin >> t
it causes a Segmentation Fault.
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int t;
cout << t << endl; // the seg fault / rte is for this
cout << t+10 << endl;
int mat[0];
int mat2[t+10];
for (int i = 0 ; i<100 ; i++) {
//cout << mat[i] << endl;
}
cout << sizeof(mat)/sizeof(int) << endl;
cout << sizeof(mat2)/sizeof(int) << endl;
cin >> t;
return 0;
}
What is happening in it?