簡體   English   中英

為什么我們使用點/箭頭運算符來訪問 c 中的結構變量

[英]why we are using dot/arrow operator to access structure variables in c

我不知道為什么我們使用它來訪問變量。 有什么標准嗎? 如果有它們是什么?

#include <stdio.h>
struct st {
  int i;
  char ch;
} s;
int main() {
  s.i = 10;
  printf("%d\n", s.i);
}

點運算符和箭頭運算符不一樣:

點運算符采用結構的屬性。
箭頭運算符采用結構的屬性,您使用的指針是指。

These two lines are the same thing:
(*(*(*a).b).c).d

a->b->c->d

它看起來更實用,更好看,否則你必須使用頂部的那個看起來很難閱讀,所以我們使用 -> 運算符,因為它更簡單。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM