c - passing double pointer as argument -


i wanted use double pointer. but, please tell me did wrong here. value n not update after function called. expecting 30 still see 10.

int main(int argc, char **argv) {     int n = 10;     int *ptr = &n;     int **ptr2ptr = &ptr;     function(&ptr2ptr);     printf("%d", n);     return 0; }  void function(int *num) {     *num = 30;  } 

you passing triply indirected integer function function. &ptr2ptr address of pointer pointer integer. did not define nor declare function before calling main. incorrect in c99, supported in ansi c , implicitly declares function take number of arguments of types , returning int. should move definition of function before main , change to:

void function(int ***num) {     ***num = 30;  } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -