fork download
  1. #include<stdio.h>
  2.  
  3. void modify(int p, int* q, int* r);
  4.  
  5. int main() {
  6. int a = 1;
  7. int b = 2;
  8. int x = 3;
  9. int* c = &x;
  10.  
  11. printf("a = %d, b = %d, *c = %d\n", a, b, *c);
  12.  
  13. modify(a, &b, c); // a is passed by value, b is passed by reference by creating a pointer (call by value),
  14. // c is a pointer passed by value
  15. // b and x are changed
  16. printf("a = %d, b = %d, *c = %d\n", a, b, *c);
  17.  
  18. return 0;
  19. }
  20.  
  21. void modify(int p, int* q, int* r)
  22. {
  23. p = 25; // passed by value: only the local parameter is modified
  24. *q = 26; // passed by value or reference, check call site to determine which
  25. *r = 27; // passed by value or reference, check call site to determine which
  26. }
Success #stdin #stdout 0s 9416KB
stdin
Standard input is empty
stdout
a = 1, b = 2, *c = 3
a = 1, b = 26, *c = 27