Advertisement
Guest User

Untitled

a guest
Sep 24th, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int x = 2;
  8. int *ptr = &x;
  9. (*ptr)++;
  10. cout << (*ptr);//prints out 3
  11. }
  12.  
  13. VS
  14.  
  15. #include <iostream>
  16.  
  17. using namespace std;
  18.  
  19. int main()
  20. {
  21. int x = 2;
  22. int *ptr = &x;
  23. ptr++;
  24. cout << (*ptr); //undefined behavior, prints out what ever is in the memory spot after the address of x, which could be anything
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement