Reference problem

Write a function that takes pointer argument, modifies what the pointer points and then returns the destination of the pointer as a reference.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include<iostream>

using namespace 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?
Topic archived. No new replies allowed.