問題在標題中給出: 我不知道爲什麼會發生這種情況。 有人可以告訴我這些技巧是如何工作的。一個地址如何可以存儲多個值?
這裏是我的代碼:
#include<stdio.h>
int main(){
int a = 320;
char *ptr;
printf("%p\n",&a);
ptr =(char *)&a;
printf("%p\n",ptr);
printf("%d\n",a);
printf("%d\n",*ptr);
return 0;
}
輸出:
0x7fffc068708c
0x7fffc068708c
320
64
檢查這個問題。有一個很好的解釋http://stackoverflow.com/questions/10262217/dynamic-memory-allocation-in-c-issues – abhi 2013-05-02 07:07:25