I did exactly this on a different computer and got a segmentation fault error:
int * ptr_to_int;
*ptr_to_int = 34;
cout << *ptr_to_int << endl;
However, I'm doing it now on my computer and it works just fine. What could be the reason for this?
My main question is: is it strictly necessary to use the "new" operator to reserve memory for this pointer? As in:
int * ptr_to_int = new int;
*ptr_to_int = 34;
cout << *ptr_to_int << endl;
I know "new" must be used when using pointers to structures. Is it also necessary with basic types?