Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.16 KB | None | 0 0
  1. /* OUTPUT
  2. ------
  3. 0x7ffebdd9a390
  4. 1
  5. ------
  6. 1
  7. 0x7ffebdd9a29c
  8. ------
  9. (nil)
  10. ------
  11. 0x7ffebdd9a29c
  12. 0x7ffebdd9a29c
  13. ------
  14. 2
  15. */
  16. #include <stdio.h>
  17. void main(){
  18.  
  19. int integerValue = 1; //integerValue is VALUE
  20.  
  21. int* integerPointer; //integerPointer is a POINTER
  22. printf("------\n");
  23. printf("%p\n", integerPointer); //Outputs address OS allocated for it
  24. printf("%d\n",*integerPointer); //Outputs whatever in that memory space from before.
  25.  
  26. printf("------\n");
  27. printf("%d\n",integerValue); //1
  28. printf("%p\n", &integerValue); //The address of where integerValue exists. & means the point$
  29.  
  30. integerPointer = NULL;
  31. printf("------\n");
  32. printf("%p\n",integerPointer); //0 or NULL basically address to nothing.
  33. integerPointer = &integerValue; //We can assign integerValue's address to integerPointer
  34.  
  35. printf("------\n");
  36. printf("%p\n", &integerValue); //Now both output the same address in memory
  37. printf("%p\n",integerPointer); //You can change that memory using either variable.
  38. *integerPointer = 2; //* means change data at pointer's location
  39. printf("------\n");
  40. printf("%d\n",integerValue);//integerValue is now 2 since the memory it uses was changed.
  41.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement