previous | start | next

14. Pointer Arithmetic

An integer can be added to a pointer and the result is again an address. The idea is that if a pointer p stores the address of some integer, then p + 1 should be the address of the next integer!

Since an integer is typically 4 bytes, to calculate the actual address computed by p + 1, the integer is scaled (multiplied by) 4 (the size of an integer).

For example, if p is initialized with the address of an array element a[0], then p+1 will be the address of a[1].



previous | start | next