I just started learning c++ and encountered some weird behavior, the results of the below code is:
0x7ffee729ba58
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
Code:
int i = 23;
int &ref_i = i;
cout << &i << endl;
int *p;
cout << *p << endl;
But if I remove the second line int &ref_i = i;
, the reuslt is as expected:
0x7ffee262ca58
0
Process finished with exit code 0
Why? Thanks!