我試着玩一些指針來指向'i'的指針,我發現有兩個不同的地址分配給聲明%u和%lu,%llu。怎麼可能是一個變量可以在執行相同的實例有兩個不同的地址 -變量如何在同一時間點有兩個不同的地址?
#include <stdio.h>
int main(void)
{
int i;
float f;
printf("\nEnter an integer:\t");
scanf("%d",&i);
printf("\nValue of address of i=%u",&i);
printf("\nvalue of address of i=%d",&i);
printf("\nValue of address of i=%lu",&i);
printf("\nValue of address of i=%llu",&i);
printf("\nvalue of i=%d",i);
printf("\nvalue of i=%u",i);
printf("\nvalue of i=%lu",i);
printf("\nvalue of i=%llu\n",i);
}
這是輸出 -
[email protected]:~/Desktop/Daily programs/pointers$ ./pointer001
Enter an integer: 12
Value of address of i=1193639268
value of address of i=1193639268
Value of address of i=140725797092708
Value of address of i=140725797092708
value of i=12
value of i=12
value of i=12
value of i=12
在這裏,我們可以清楚地看到,%u和%d的地址是1193639268(儘管%d和%u的輸出在所有情況下可能不相等),%lu和%llu的輸出是140725797092708,它的物理意義是什麼。
細節:用於打印'void *'指針的適當格式說明符是'「%p」'。 ''%p「'可能不適用於'int *',但常見。 – chux
@chux好點。我已經添加了這個細節 – dbush