#include <stdio.h>
main()
{
int a[] ={ 1,2,3,4,5,6,7};
char c[] = {' a','x','h','o','k'};
printf("%d ", (&a[3]-&a[0]));
}
The output of the program is 3. However , the difference in the outputs of values obtained below is 12.Can someone please explain the ambiguity.
#include <stdio.h>
main()
{
int a[] ={ 1,2,3,4,5,6,7};
char c[] = {' a','x','h','o','k'};
printf("%d %d ", &a[3],&a[0]);
}
This is called pointer arithmetics. The result is the values divided by
sizeof(int)If the difference in bytes is 12, and the size of
intis 4, than the result is12/4=3BTW, when printing addresses use the format specifier
%p: