- Example
C program:
int main(int argc, char *argv[])
{
int a[10];
int *p;
p = &a[0]; // p points to variable a[0]
printf("p = %lu, &a[%d] = %lu\n", p, 0, &a[0] );
printf("p + 1 = %lu, &a[%d] = %lu\n", p+1, 1, &a[1] );
printf("p + 2 = %lu, &a[%d] = %lu\n", p+2, 2, &a[2] );
printf("p + 3 = %lu, &a[%d] = %lu\n", p+3, 3, &a[3] );
}
|
Output:
p = 4290769444, &a[0] = 4290769444 (increased by 4 !!!)
p + 1 = 4290769448, &a[1] = 4290769448 (sizeof(int) = 4)
p + 2 = 4290769452, &a[2] = 4290769452
p + 3 = 4290769456, &a[3] = 4290769456
|
|