Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //41_PointersAndMath
- #include <iostream>
- using namespace std;
- int main(){
- int bucky[5];//each int takes 4 bytes
- int *bp0=&bucky[0];
- int *bp1=&bucky[1];
- int *bp2=&bucky[2];
- cout<<"bp0 is at "<<bp0<<endl;//0x22fee0
- cout<<"bp1 is at "<<bp1<<endl;//0x22fee4
- cout<<"bp2 is at "<<bp2<<endl;//0x22fee8
- bp0=bp0++;//one element away
- //!!!!bp0 is a pointer
- // it does not change the memory address of that pointer
- //it change what element it's pointing to
- cout<<"bp0 is now at "<<bp0<<endl;//0x22fee4
- bp0=bp0+1;//one more element away
- cout<<"but for now bp0 is at "<<bp0<<endl;//0x22fee8
- }
Advertisement
Add Comment
Please, Sign In to add comment