gpt4 book ai didi

c - C 中结构解引用运算符的更复杂表示法是 ->?

转载 作者:行者123 更新时间:2023-11-30 21:30:54 26 4
gpt4 key购买 nike

我这里有一个考试问题,询问:

“C 运算符 -> 是更复杂表示法的简写。解释使用 -> 或更复杂表示法的情况。编写更复杂表示法的示例。”

我不确定考官在这里寻找什么。我的印象是,只有一种方法可以表示结构取消引用,那就是 ->。有人可以帮忙吗?

最佳答案

可以使用->(*). 来取消引用。请参阅示例

struct point {
int x;
int y;
};
struct point my_point = { 3, 7 };
struct point *p = &my_point; /* To declare and define p as a pointer of type struct point,
and initialize it with the address of my_point. */

(*p).x = 8; /* To access the first member of the struct */
p->x = 8;

很可能你的老师要求的是(*p).x = 8;

关于c - C 中结构解引用运算符的更复杂表示法是 ->?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22918768/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com