An example of pointer arithmetic

This is an example C program demonstrating pointer arithmetic.

#include <stdio.h>

int main ()
{
    int x;
    int * x_p;

    x_p = x;
    printf ("%p\n", x_p);
    x_p = x_p + 1;
    printf ("%p\n", x_p);
    return 0;
}

(download)

The output of the example looks like this:

0xbfbfea78
0xbfbfea7c

Notice here that the second value is four bytes beyond the first value.


Copyright © Ben Bullock 2009-2017. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com). / Privacy / Disclaimer