ya_zay4eg

//41_PointersAndMath

Jun 24th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. //41_PointersAndMath
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main(){
  7.    int bucky[5];//each int takes 4 bytes
  8.    int *bp0=&bucky[0];
  9.    int *bp1=&bucky[1];
  10.    int *bp2=&bucky[2];
  11.  
  12.    cout<<"bp0 is at "<<bp0<<endl;//0x22fee0
  13.    cout<<"bp1 is at "<<bp1<<endl;//0x22fee4
  14.    cout<<"bp2 is at "<<bp2<<endl;//0x22fee8
  15.  
  16.    bp0=bp0++;//one element away
  17.    //!!!!bp0 is a pointer
  18.    // it does not change the memory address of that pointer
  19.    //it change what element it's pointing to
  20.    cout<<"bp0 is now at "<<bp0<<endl;//0x22fee4
  21.    bp0=bp0+1;//one more element away
  22.    cout<<"but for now bp0 is at "<<bp0<<endl;//0x22fee8
  23. }
Advertisement
Add Comment
Please, Sign In to add comment