C中结构体名前加“*”是什么地址
typedef struct PeoInfo
{
char name[20];
int age;
char sex[5];
char tele[12];
char addr[30];
}
struct PeoInfo c[10] = {0};
printf("p=%x\n", *c);
printf("p=%x\n", c[0]);
在这种情况下,sizeof(c)
和 sizeof(*c)
会产生不同的结果。 在我看来,c
是数组的条目。但是*c
是什么? sizeof(*c)
的结果是 PeoInfo
的大小。使用printf
打印*c
和c[0]
的地址时,结果也不同。 我对此真的很困惑。
typedef struct PeoInfo
{
char name[20];
int age;
char sex[5];
char tele[12];
char addr[30];
}
struct PeoInfo c[10] = {0};
printf("p=%x\n", *c);
printf("p=%x\n", c[0]);
In this situation, sizeof(c)
and sizeof(*c)
have different results.
In my point of view, c
is the entry of the array. But what is the *c
? The result of sizeof(*c)
is the size of PeoInfo
. When using printf
to print the address of *c
and c[0]
, the result is also different.
I am really confused about it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在此表达式 *c 中,数组指示符 c 隐式转换为指向 struct PeoInfo * 类型的第一个元素的指针,并应用取消引用运算符生成该类型的对象
结构 PeoInfo
。因此,表达式
sizeof( *c )
(其中表达式*c
未求值,仅确定其类型)会产生struct PeoInfo 类型的对象的大小
。由于下标运算符 c[0] 的计算方式与 *( c + 0 ) 相同,因此这些 printf 语句将输出相同的值
In this expression
*c
the array designator c is implicitly converted to a pointer to its first element of the typestruct PeoInfo *
and applying the dereference operator yields an object of the typestruct PeoInfo
.So the expression
sizeof( *c )
where the expression*c
is not evaluated and only its type is determinated yields the size of an object of the typestruct PeoInfo
.As the subscript operator c[0] is calculated like *( c + 0 ) that is the same as *c then these printf statements will output the same value