uni

University stuff
git clone git://git.margiolis.net/uni.git
Log | Files | Refs | README | LICENSE

ptrs_ex1.c (414B)


      1 #include <stdio.h>
      2 
      3 /* 
      4  * Assign a pointer to a variable and change its 
      5  * value using both the variable and the pointer. Then
      6  * print their value and addresses
      7  */
      8 
      9 int
     10 main(int argc, char *argv[])
     11 {
     12         int *ptr, x = 10;
     13 
     14         ptr = &x;
     15         x += 20;
     16         *ptr += 30;
     17 
     18         printf("x: val: %d | addr: %p\n", x, &x);
     19         printf("ptr: val: %d | addr: %p\n", *ptr, ptr);
     20 
     21         return 0;
     22 }