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

1 Answer

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

 



answered Jun 20, 2024 by avibootz

Related questions

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