标签:指针 读取 float 类型 运算 组元 表示 name struct
#include <stdio.h>
main()
{
struct student
{
char name[20]; //姓名
int num; //学号
int age; //年龄
char group; //所在小组
float score; //成绩
} stu1 = { "Tom", 12, 18, ‘A‘, 136.5 },*pstu = &stu1; //读取结构体成员的值
printf("%s的学号是%d,年龄是%d,在%c组,今年的成绩是%.1f!\n", (*pstu).name, (*pstu).num, (*pstu).age, (*pstu).group, (*pstu).score); //括号不可省略,点运算符优先级高于星号运算符
printf("%s的学号是%d,年龄是%d,在%c组,今年的成绩是%.1f!\n", pstu->name,pstu->num, pstu->age, pstu->group,pstu->score); //"->"指向运算符,表示p所指向的结构体变量的某个成员
}
Tom的学号是12,年龄是18,在A组,今年的成绩是136.5!
Tom的学号是12,年龄是18,在A组,今年的成绩是136.5!
struct student stu[3];
标签:指针 读取 float 类型 运算 组元 表示 name struct
原文地址:http://www.cnblogs.com/qsyj0522/p/8000653.html