我試圖找出之間的差異和「 - >」的C語言數據訪問風格。例如,
struct div{
int quo;
int rem;
};
1)使用 「 - >」
struct div *d = malloc(sizeof(struct div));
d->quo = 8/3;
d->rem = 8%3;
printf("Answer:\n\t Quotient = %d\n\t Remainder = %d\n-----------\n",d->quo,d->rem);
2)使用 「」
struct div d;
d.quo = 8/3;
d.rem = 8%3;
printf("Answer:\n\t Quotient = %d\n\t Remainder = %d\n-----------\n",d.quo,d.rem);
我得到了這兩種情況相同的輸出。
答:智商= 2餘數= 2
如何這兩種方法是內部的工作?什麼時候應該使用哪一個? 我試過在互聯網上搜索它,但幫助不大。任何相關的鏈接也表示讚賞。
他們在內存中的存儲還有什麼區別嗎?
有這個問題反過來_StackOverflow_地方一個完美的答案,讓我覺得它現在.. –
[這是另一個解釋](http://stackoverflow.com/questions/1238613/what-is-the-difference-between-the-dot-o perator-and-in-c)在C++上下文中的差異(C部分仍然存在)。 –
你的回答在於你的問題本身。它不在'.'和' - >'之間,而是數據訪問的上下文。 – NeonGlow