Pass Address of pointer to function

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

void myfunc(int* ); // what do i put in these parameters to accept a mem loc of a pointer

int main ()
{
    int x = 5;
    
    int* ptr;
    
    myfunc(&ptr); ///This is how i want to pass the pointer to the function! 
    
    
    return 0;
}

void myfunc(int*)
{
    
}


SOLUTION:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std;

//Purpose to create a function that returns a pointer to a pointer
int** myfunc(int**);

int main ()
{
    int x = 5;
    int* ptr;
    int** ptrp;
    
    
    cout << &ptr << endl;
    
    ptrp = myfunc(&ptr);
    
    cout << endl;
    cout << ptrp << endl;

    
    
    cout << endl << endl;

    return 0;
}

int** myfunc(int** intpp)
{
    cout << intpp;
    
    return *&intpp;
}
Last edited on
surely the memory address is just an integer?
Face palm on Line 32, actually that whole function OP. Did you have an actual question here before your edit?
I found out how to do it before anybody replied so i figured I add the answer instead of delete the post.
Topic archived. No new replies allowed.