home *** CD-ROM | disk | FTP | other *** search
- //: C03:PointerArithmetic.cpp
- // From Thinking in C++, 2nd Edition
- // Available at http://www.BruceEckel.com
- // (c) Bruce Eckel 1999
- // Copyright notice in Copyright.txt
- #include <iostream>
- using namespace std;
-
- #define P(EXP) \
- cout << #EXP << ": " << EXP << endl;
-
- int main() {
- int a[10];
- for(int i = 0; i < 10; i++)
- a[i] = i; // Give it index values
- int* ip = a;
- P(*ip);
- P(*++ip);
- P(*(ip + 5));
- int* ip2 = ip + 5;
- P(*ip2);
- P(*(ip2 - 4));
- P(*--ip2);
- } ///:~
-