#include<stdio.h>
int main()
{
int i=10,j=20,diff;
diff=&j-&i;
printf("\nAddress of i=%u Address of j=%u",&i,&j);
printf("\nDifference of address i and j is %d\n",diff);
return 0;
}
The output I got is:
Address of i=3012788 Address of j=3012776
Difference of address i and j is -3
But the difference between the addresses here is 2.
When I do diff=&i-&j
, I get the following output:
Address of i=2751740 Address of j=2751728
Difference of address i and j is 3
But the difference here between the addresses is 12.
When two integer variables are declared, its not necessary for the second variable to occupy the next four bytes of the address occupied by the first variable. But why the differences are not actually what it has to be?