When i execute this code
#include<stdio.h>
int main() {
int (*x)[5];
printf("\nx = %u\nx+1 = %u\n&x = %u\n&x + 1 = %u",x,x+1,&x,&x+1);
}
This is the output in C or C++:
x = 134513520
x+1 = 134513540
&x = 3221191940
&x + 1 = 3221191944
Please explain. Also what is the difference between:
int x[5] and int (*x)[5] ?
int x[5]is an array of 5 integersint (*x)[5]is a pointer to an array of 5 integersWhen you increment a pointer, you increment by the size of the pointed to type.
x+1is therefore5*sizeof(int)bytes larger than justx– giving the8048370and8048384hex values with a difference of 0x14, or 20.&xis a pointer to a pointer – so when you increment it you addsizeof(a pointer)bytes – this gives thebf9b08b4andbf9b08b8hex values, with a difference of 4.