Code
#include <iostream>
using namespace std;
int* s;
int* func1(int*&m)
{
int* n=s;
m=n;
return n;
}
int* func2(int** m)
{
int* n=s;
m=&n;
return n;
}
int* func3(int* m)
{
int* s=new int(5);
m=s;
delete s;
return m;
}
int main()
{
int b=8;
int* c=NULL;
int * d=NULL;
int* p=NULL;
p=&b;
cout<<*p<<endl;
s= new int(100);
/////////////////////////////////////////////////////////////////////////////////
//func1
/////////////////////////////////////////////////////////////////////////////////
cout<<"\nfunc1\n"<<endl;
d=func1 (c);
if (d==NULL)
{
cout<<"This is a null pointer!\nd addr:"<<d;
}
else
{
cout<<"d:\n"<<"addr:"<<d<<endl;
cout<<"value:"<<*d<<endl;
cout<<"pointer addr:"<<&d<<endl;
}
cout<<endl;
if (c==NULL)
{
cout<<"This is a null pointer!\nc addr:"<<c;
}
else
{
cout<<"c:\n"<<"addr:"<<c<<endl;
cout<<"value:"<<*c<<endl;
cout<<"pointer addr:"<<&d<<endl;
}
/////////////////////////////////////////////////////////////////////////////////
//func2
/////////////////////////////////////////////////////////////////////////////////
cout<<"\nfunc2\n"<<endl;
d=func2 (&c);
if (d==NULL)
{
cout<<"This is a null pointer!\nd addr:"<<d;
}
else
{
cout<<"d:\n"<<"addr:"<<d<<endl;
cout<<"value:"<<*d<<endl;
cout<<"pointer addr:"<<&d<<endl;
}
cout<<endl;
if (c==NULL)
{
cout<<"This is a null pointer!\nc addr:"<<c;
}
else
{
cout<<"c:\n"<<"addr:"<<c<<endl;
cout<<"value:"<<*c<<endl;
cout<<"pointer addr:"<<&d<<endl;
}
/////////////////////////////////////////////////////////////////////////////////
//func3
/////////////////////////////////////////////////////////////////////////////////
cout<<"\nfunc3\n"<<endl;
d=func3 (c);
if (d==NULL)
{
cout<<"This is a null pointer!\nd addr:"<<d;
}
else
{
cout<<"d:\n"<<"addr:"<<d<<endl;
cout<<"value:"<<*d<<endl;
cout<<"pointer addr:"<<&d<<endl;
}
cout<<endl;
if (c==NULL)
{
cout<<"This is a null pointer!\nc addr:"<<c;
}
else
{
cout<<"c:\n"<<"addr:"<<c<<endl;
cout<<"value:"<<*c<<endl;
cout<<"pointer addr:"<<&d<<endl;
}
delete s;
cin>>b;
return 0;
}
#include <iostream>
using namespace std;
int* s;
int* func1(int*&m)
{
int* n=s;
m=n;
return n;
}
int* func2(int** m)
{
int* n=s;
m=&n;
return n;
}
int* func3(int* m)
{
int* s=new int(5);
m=s;
delete s;
return m;
}
int main()
{
int b=8;
int* c=NULL;
int * d=NULL;
int* p=NULL;
p=&b;
cout<<*p<<endl;
s= new int(100);
/////////////////////////////////////////////////////////////////////////////////
//func1
/////////////////////////////////////////////////////////////////////////////////
cout<<"\nfunc1\n"<<endl;
d=func1 (c);
if (d==NULL)
{
cout<<"This is a null pointer!\nd addr:"<<d;
}
else
{
cout<<"d:\n"<<"addr:"<<d<<endl;
cout<<"value:"<<*d<<endl;
cout<<"pointer addr:"<<&d<<endl;
}
cout<<endl;
if (c==NULL)
{
cout<<"This is a null pointer!\nc addr:"<<c;
}
else
{
cout<<"c:\n"<<"addr:"<<c<<endl;
cout<<"value:"<<*c<<endl;
cout<<"pointer addr:"<<&d<<endl;
}
/////////////////////////////////////////////////////////////////////////////////
//func2
/////////////////////////////////////////////////////////////////////////////////
cout<<"\nfunc2\n"<<endl;
d=func2 (&c);
if (d==NULL)
{
cout<<"This is a null pointer!\nd addr:"<<d;
}
else
{
cout<<"d:\n"<<"addr:"<<d<<endl;
cout<<"value:"<<*d<<endl;
cout<<"pointer addr:"<<&d<<endl;
}
cout<<endl;
if (c==NULL)
{
cout<<"This is a null pointer!\nc addr:"<<c;
}
else
{
cout<<"c:\n"<<"addr:"<<c<<endl;
cout<<"value:"<<*c<<endl;
cout<<"pointer addr:"<<&d<<endl;
}
/////////////////////////////////////////////////////////////////////////////////
//func3
/////////////////////////////////////////////////////////////////////////////////
cout<<"\nfunc3\n"<<endl;
d=func3 (c);
if (d==NULL)
{
cout<<"This is a null pointer!\nd addr:"<<d;
}
else
{
cout<<"d:\n"<<"addr:"<<d<<endl;
cout<<"value:"<<*d<<endl;
cout<<"pointer addr:"<<&d<<endl;
}
cout<<endl;
if (c==NULL)
{
cout<<"This is a null pointer!\nc addr:"<<c;
}
else
{
cout<<"c:\n"<<"addr:"<<c<<endl;
cout<<"value:"<<*c<<endl;
cout<<"pointer addr:"<<&d<<endl;
}
delete s;
cin>>b;
return 0;
}