Advertisement
quantim

Basic Pointer Syntax

Oct 23rd, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. int main(void)
  5. {
  6.         int a = 100;
  7.         /*
  8.  *      ---------------------
  9.  *      | Memory address = &a|
  10.  *      ---------------------
  11.  *      |    a = 100         |
  12.  *      ---------------------
  13.  *      */
  14.         int *ptr = &a;
  15. /*
  16.  *      ---------------------------
  17.  *      | Memory address = ptr = &a |
  18.         ---------------------------
  19.         | *ptr = a = 100           |
  20.         ---------------------------
  21. */
  22.         // To print the VALUE at the MEMORY ADDRESS
  23.         printf("*ptr = %d\n", *ptr);
  24.         // To Print the MEMORY ADDRESS itself
  25.         printf("ptr = %p\n", (void *) ptr);
  26.         printf("&a = %p\n", &a);
  27.  
  28.         return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement