13
社区成员




定义指针的时候为什么不标明类型啊?这里为什么这么定义指针stu_prt啊?
#include <stdio.h>
struct
{
char *name;
int id;
unsigned int age;
char group;
float score;
} stu = {"张三", 1001, 16, 'A', 95.50}, *stu_prt = &stu;//这里为什么这么定义指针stu_prt啊?
int main(int argc, char** argv)
{
printf("========== 学生基本信息 ==========\n");
printf("姓名:%s\n学号:%d\n年龄:%d\n所在小组:%c\n成绩:%.2f\n",
stu_prt->name, stu_prt->id, stu_prt->age, stu_prt->group, stu_prt->score);
printf("==================================\n");
return 0;
}
“.” 点运算符的优先级高于 “*” 指针运算符的优先级
主页或者专栏有助于学习高效C语言 https://blog.csdn.net/gzplyx?type=blog
优先级问题,好细啊
#include <stdio.h>
typedef struct
{
char *name;
int id;
unsigned int age;
char group;
float score;
} Student;
int main(int argc, char** argv)
{
Student stu = {"张三", 1001, 16, 'A', 95.50};
Student *stu_prt = &stu;
printf("========== 学生基本信息 ==========\n");
printf("姓名:%s\n学号:%d\n年龄:%d\n所在小组:%c\n成绩:%.2f\n",
*stu_prt.name, *stu_prt.id, *stu_prt.age, *stu_prt.group, *stu_prt.score);
printf("==================================\n");
return 0;
}