Address difference between two integer variables in c

前端 未结 5 1215
醉梦人生
醉梦人生 2021-01-07 07:17
#include 
int main()
{
    int i=10,j=20,diff;
    diff=&j-&i;
    printf(\"\\nAddress of i=%u Address of j=%u\",&i,&j);
    printf(\"         


        
5条回答
  •  感情败类
    2021-01-07 07:33

    You are using pointer arithmetic. Because int is 4 bytes on your machine, result * 4 is the distance between the two address. However you can apply conversion like (int) on the pointers to get what you expected.

提交回复
热议问题