Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int i1 = 5, i2 = 3;
- const int* pi1 = &i1;
- int* const pi2 = &i2;
- // the next line prints 5 3
- cout << *pi1 << ' ' << *pi2 << endl;
- // the next line is compile error - try to modify to const int
- // *pi1 = 7;
- pi1 = &i2;
- // the next line prints 3 3
- cout << *pi1 << ' ' << *pi2 << endl;
- // the next line is compile error - try to modify to const int pointer
- // pi2 = &i2;
- pi1 = &i1;
- *pi2 = 7;
- // the next line prints 5 7
- cout << *pi1 << ' ' << *pi2 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement