Guest User

Untitled

a guest
Jan 17th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. int* a = NULL;
  2. int* b = *a;
  3.  
  4. b = new int(5);
  5. std::cout << *a;
  6. std::cout << *b;
  7.  
  8. int* a = null; //Global variable
  9. int* b = null; //Global variable
  10.  
  11. int* returnInt(int position)
  12. {
  13. switch(position)
  14. {
  15. case 0:
  16. return a;
  17. case 1:
  18. return b;
  19. }
  20. }
  21.  
  22. some other function -
  23.  
  24. int* c = returnInt(0); // Get Global a
  25.  
  26. if (c == null)
  27. c = new int(5);
  28.  
  29. int* a = NULL;
  30. int* b = *a; //here you dereference a NULL pointer, undefined behavior.
  31.  
  32. int* b = new int(5);
  33. int*& a = b; //a is a reference to pointer to int, it is a synonym of b
  34. std::cout << *a;
  35. std::cout << *b;
  36.  
  37. int* b = new int(5);
  38. int& a = *b; //a is a reference to int, it is a synonym of `*b`
  39. std::cout << a; //prints 5
  40. std::cout << *b; //prints 5
  41. a = 4;
  42. std::cout << a; //prints 4
  43. std::cout << *b; //prints 4
  44.  
  45. int* b = NULL;
  46. int*& a = b;
Add Comment
Please, Sign In to add comment