D
Deepchand.P
Friends i did this prog in VS 2005.
#include <iostream>
using namespace std;
int* f();
int main()
{
int *k = f();
cout<<"Inside int main() "<<endl<<"k = "<<k<<endl<<"*k =
"<<*k<<endl<<"&k = "<<&k<<endl<<endl;
cout<<"Calling cout<<*f()"<<endl<<*f()<<endl<<endl;
return 0;
}
int* f()
{
int m=100;
cout<<"Inside int* f() "<<endl<<"m = "<<m<<endl<<"&m =
"<<&m<<endl<<endl;
return(&m);
}
y does we still get the value 100 by using *f(); whats actually
happening there. From what i have understood so far the value of a
variable becomes garbage when the variable goes out of scope.
correct me if am wrong and plz explain me the working of this program.
#include <iostream>
using namespace std;
int* f();
int main()
{
int *k = f();
cout<<"Inside int main() "<<endl<<"k = "<<k<<endl<<"*k =
"<<*k<<endl<<"&k = "<<&k<<endl<<endl;
cout<<"Calling cout<<*f()"<<endl<<*f()<<endl<<endl;
return 0;
}
int* f()
{
int m=100;
cout<<"Inside int* f() "<<endl<<"m = "<<m<<endl<<"&m =
"<<&m<<endl<<endl;
return(&m);
}
y does we still get the value 100 by using *f(); whats actually
happening there. From what i have understood so far the value of a
variable becomes garbage when the variable goes out of scope.
correct me if am wrong and plz explain me the working of this program.