gpt4 book ai didi

c - 为什么我可以使用别名作为标识符的名称?

转载 作者:太空宇宙 更新时间:2023-11-04 01:58:24 25 4
gpt4 key购买 nike

为什么 C 允许声明一个来自 student 类型的指针(studenttypedef 的结果)名称为 学生?

typedef struct
{
char* name;
int age;
}
student;

student s = {"Mark", 22};
student* student = &s;
printf("%i\n", student->age);

为什么前面的代码可以工作,而下面的代码不行?

int x = 3;
int* int = &x
printf("%i\n", *int);

最佳答案

您正在使用保留关键字 int 作为变量名。使用其他东西,它会起作用。

int x = 2 ;
int *y = &x ;
printf("%d", *y);

请注意,变量名或函数名不能使用关键字。

编辑:你的学生类型代码会报错:See Here错误清楚地表明 'student' redeclared as different kind of symbol

关于c - 为什么我可以使用别名作为标识符的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30557079/

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