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
Post a Comment