How to pass the address of a pointer to a function in C++

1 Answer

0 votes
#include <iostream>
 
void changeValue(int** p) {
    **p = 700;
}
   
int main()
{
    int n = 12;
    int* p = &n;
   
    std::cout << *p << " " << n << "\n";
   
    changeValue(&p);
   
    std::cout << *p << " " << n << "\n";
}
      
      
      
      
/*
run:
    
12 12
700 700
       
*/

 



answered Feb 23, 2022 by avibootz

Related questions

1 answer 100 views
1 answer 135 views
1 answer 111 views
2 answers 200 views
1 answer 134 views
...