#include<iostream>
usingnamespace std;
int & funct1(int * pnt)
{
*pnt = 5;
int &y =pnt;
return y;
}
int main()
{
int * ont;
int x =6;
//int & z;
ont = &x;
int &z=funct1(ont);
cout << z << " z" << endl;
system("pause");
return 0;
}
I am trying to solve the above problem but getting error "invalid initialisation of reference of type 'int&' from expression of type 'int'". Please correct me.
These instructions are really weird, but how I interpret them is like:
1 2 3 4 5
int & funct1(int * pnt)
{
*pnt = 5;
return *pnt; //Dereference pointer to get the entity it points to. Function returns reference of this entity.
}
But I don't even know for sure what it is asking. Is it asking to return the address of the pointer? Is it asking to return the pointee? Is it asking to return the address of the pointee?