fork download
  1. #include <stdio.h>
  2. void pointer_inc(int *p1, int *p2)
  3. {
  4. printf("The address of p1 is %p\n", &p1);
  5. printf("The value of p1 is %p\n", p1);
  6. printf("The address of p2 is %p\n", &p2);
  7. printf("The value of p2 is %p\n", p2);
  8. *p1 += 1;
  9. p1 = p2;
  10. *p1 += 2;
  11. }
  12. int main(void)
  13. {
  14. int i, j;
  15. int *iptr = &i;
  16.  
  17. scanf("%d", &i);
  18. scanf("%d", &j);
  19. printf("The address of i is %p\n", &i);
  20. printf("The address of j is %p\n", &j);
  21. printf("The address of iptr is %p\n", &iptr);
  22. printf("i = %d, j = %d\n", i, j);
  23. pointer_inc(iptr, &j);
  24. printf("i = %d, j = %d\n", i, j);
  25. *iptr += 5;
  26. printf("i = %d, j = %d\n", i, j);
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0.01s 5320KB
stdin
10 20
stdout
The address of i is 0x7ffe9b7c9218
The address of j is 0x7ffe9b7c921c
The address of iptr is 0x7ffe9b7c9220
i = 10, j = 20
The address of p1 is 0x7ffe9b7c91f8
The value of p1 is 0x7ffe9b7c9218
The address of p2 is 0x7ffe9b7c91f0
The value of p2 is 0x7ffe9b7c921c
i = 11, j = 22
i = 16, j = 22