Advertisement
uopspop

Untitled

May 5th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5.  
  6.     int a = 10;
  7.     int b = 100;
  8.    
  9. // 
  10.     int * ptr1 = &a;
  11.     *ptr1 = 20;
  12.     cout << "ptr1: "<<  *ptr1 << endl;
  13.     ptr1 = &b;
  14.     cout << "ptr1: "<< *ptr1 << endl;
  15.  
  16.  
  17. // 
  18.     a = 10;
  19.     b = 100;
  20.     const int * ptr2 = &a;
  21.     //*ptr2 = 20; // error
  22.     ptr2 = &b;
  23.     cout << "ptr2: "<< *ptr2 << endl;
  24.  
  25. //
  26.     a = 10;
  27.     b = 100;
  28.     int * const ptr3 = &a;
  29.     *ptr3 = 20;
  30.     //ptr3 = &b;// error
  31.     cout << "ptr3: "<< *ptr3 << endl;
  32.  
  33. //
  34.     a = 10;
  35.     b = 100;
  36.     const int * const ptr4 = &a;
  37.     //*ptr4 = 20; // error
  38.     //ptr3 = &b;// error
  39.     cout << "ptr4: "<< *ptr4 << endl;
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement