#include #include // Demonstrate pointer arithmetic and accessing elements of arrays. void array_demo1() { short i; int *x = malloc(sizeof(int) * 6); // int *a, y; // type of a is int*, type of y is int printf( "size of a is %lu, size of y is %lu\n", sizeof(a), sizeof(y) ); for (i = 0; i < 6; i++) { x[i] = i*10; } // pointer arithmetic // a + 1 is bytes beyond a because a is a pointer to ints and ints // are 4 bytes. This is a little on the complicated side until you // look at it like this: a[i] is equivalent to *(a+i), which means // go i elements beyond the beginning of the array and dereference // it. for (i = 0; i < 6; i++) { printf( "a[i] is at %p = %p\n", &(a[i]), a+i ); } } int main (int argc, char *argv[]) { array_demo1(); }