Pointer Arithmetics

Pointer arithmetic is frequently used in C programs which means that a C programmer must know how to do this. The basic concept is that a pointer variable (which contains the address of some piece of memory) can be modified by the programmer. Here really shows that pointers are special types because incrementing a pointer can give some surprising results.

int k= 3;
int* ptr = &k;  // ptr now contains the address of k
ptr++;  // incrementing the pointer makes it point to 
        // address of k PLUS 4 byte. 

The reason for this is that pointer arithmetic calculates with the SIZE OF THE TYPE the pointer is pointing to. The formula is: pointer + x == ptr + (x * sizeof(pointerType)