RicardasSim

pointer to pointer

Nov 5th, 2019
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void f1(int *v)
  5. {
  6.     printf("f1: %d\n", *v);
  7. }
  8.  
  9. void f2(int *v1, int **v2)
  10. {
  11.     *v2 = v1;
  12. }
  13.  
  14.  
  15. int main()
  16. {
  17.  
  18.     int a = 123;
  19.     int b = 789;
  20.     int *p;
  21.  
  22.     p=&a;
  23.  
  24.     printf("a: %d\n", a);
  25.     printf("b: %d\n", b);
  26.  
  27.     f1(p);
  28.  
  29.     printf("*p: %d\n", *p);
  30.  
  31.     f2(&b, &p);
  32.  
  33.     printf("*p: %d\n", *p);
  34.  
  35.     return 0;
  36. }
  37.  
  38. /*
  39. output:
  40.  
  41. a: 123
  42. b: 789
  43. f1: 123
  44. *p: 123
  45. *p: 789
  46.  
  47. */
Advertisement
Add Comment
Please, Sign In to add comment