the public pointer member get assigned a strange value every time any function gets called.. it's not the constructor called because then the value should be changed or at least the pointer address should change pointer directs to the same address but the value changes what happened?
class whathappened {
public:
int * a;
whathappened();
void print();
};
whathappened::whathappened() {
int b = 23;
a = &b;
}
void whathappened::print() {
cout << a << " " << *a << endl;
}
int main() {
whathappened sam;
cout << sam.a << " " << *sam.a << endl;
sam.print();
cout << sam.a << " " << *sam.a << endl;
while (1) {}
}
0133F650 23
0133F650 -858993460
0133F650 -858993460