C++ examples for Data Type:Pointer
Add or subtract an integral value and a pointer.
#include <iostream> using namespace std; #define P(EX) cout << #EX << ": " << EX << endl; int main() {//from w w w .ja v a 2s.co m 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); P(ip2 - ip); // Yields number of elements }