fork download
  1. #include <stdio.h>
  2.  
  3. void function1(int*); // so the compiler knows what the function looks like.
  4. void function2(int*);
  5.  
  6. int main() {
  7. int varInMain = 0; // lets call it something distinct
  8. printf("varInMain starts with %d, it's location in memory is %p.\n",
  9. varInMain, &varInMain);
  10.  
  11. function1(&varInMain);
  12.  
  13. printf("varInMain is %d after calling function1.\n", varInMain);
  14.  
  15. return 0;
  16. }
  17.  
  18. void function1(int* func1ptr) {
  19. printf("function1: func1ptr points to memory location %p, which contains %d.\n",
  20. func1ptr, *func1ptr);
  21. *func1ptr = 1010;
  22. function2(func1ptr);
  23. }
  24.  
  25. void function2(int* func2ptr) {
  26. printf("function2: func2ptr points to memory location %p, which contains %d.\n",
  27. func2ptr, *func2ptr);
  28. *func2ptr = 123;
  29. }
  30.  
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
varInMain starts with 0, it's location in memory is 0xbfef2fdc.
function1: func1ptr points to memory location 0xbfef2fdc, which contains 0.
function2: func2ptr points to memory location 0xbfef2fdc, which contains 1010.
varInMain is 123 after calling function1.