Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int* a = NULL;
- int* b = *a;
- b = new int(5);
- std::cout << *a;
- std::cout << *b;
- int* a = null; //Global variable
- int* b = null; //Global variable
- int* returnInt(int position)
- {
- switch(position)
- {
- case 0:
- return a;
- case 1:
- return b;
- }
- }
- some other function -
- int* c = returnInt(0); // Get Global a
- if (c == null)
- c = new int(5);
- int* a = NULL;
- int* b = *a; //here you dereference a NULL pointer, undefined behavior.
- int* b = new int(5);
- int*& a = b; //a is a reference to pointer to int, it is a synonym of b
- std::cout << *a;
- std::cout << *b;
- int* b = new int(5);
- int& a = *b; //a is a reference to int, it is a synonym of `*b`
- std::cout << a; //prints 5
- std::cout << *b; //prints 5
- a = 4;
- std::cout << a; //prints 4
- std::cout << *b; //prints 4
- int* b = NULL;
- int*& a = b;
Add Comment
Please, Sign In to add comment