Advertisement
dmilicev

change_variable_via_pointer_v1.c

Jun 11th, 2020
158
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3.     change_variable_via_pointer_v1.c
  4.  
  5.  
  6.     You can find all my C programs at Dragan Milicev's pastebin:
  7.  
  8.     https://pastebin.com/u/dmilicev
  9.  
  10. */
  11.  
  12. #include <stdio.h>
  13.  
  14. int main(void)
  15. {
  16.     int a, b;
  17.     int *pa, *pb;
  18.  
  19.     a = 2;  // initialization
  20.     b = 3;
  21.  
  22.     printf("\n a = %d \t b = %d \n", a, b);
  23.  
  24.     pa = &a;    // pa is pointer to a. It is memory address where value of a is stored.
  25.     pb = &b;
  26.  
  27.     *pa = 4;    // changing value of a by its pointer pa
  28.     *pb = 5;
  29.  
  30.     printf("\n a = %d \t b = %d \n", a, b);
  31.  
  32.     // or, by pointers
  33.  
  34.     printf("\n a = %d \t b = %d \n", *pa, *pb);
  35.  
  36.  
  37.     return 0;
  38.  
  39. } // main()
Advertisement
RAW Paste Data Copied
Advertisement