priyaranjan
Right off the assembly line
Code:
#include<iostream>
using namespace std;
class test
{
public:
int* i ;
test(int k)
{
i=&k;
}
};
int main()
{
test p(2);
cout<<"for 1st time *(p.i) :"<< *(p.i);
cout<<"\n";
cout<<"for 2nd time *(p.i) :"<< *(p.i);
cout<<"\n";
cout<<"for 3rd time *(p.i) :"<< *(p.i);
return 0;
}
Hi ,
The above c++ code that i compiled in visual c++,i got the following out put
output
for 1st time*(p.i) :2
for 2nd time *(p.i):20609120
for 3rd time *(p.i) :20609120
The first output is ok,but in 2nd and 3rd the out put is garbage .could any one please explain why this garbage values are coming in 2nd and 3rd?