标签:char code typename hang mat 数据类型 lib 区别 定义数据
struct student { int num;
float MathScore; float EnlishScore; }stu1;
也可以用typedef来定义
typedef struct student { int num;
float MathScore; float EnlishScore; }stu;
struct student { int num; float MathScore; float EnlishScore; }stu1,*stu2,stu3[10];
stu1 = { 1,66,88 }; printf("%d\n", stu1.num); printf("%f\n", stu1.MathScore); printf("%f\n", stu1.EnlishScore);
#include <stdio.h> struct student { int num; float MathScore; float EnlishScore; }; int main() { student stu1; stu1 = { 12, 66.6,76.5 }; student *pstu = &stu1; printf("学号是%d,今年的数学成绩是%.1f,今年的英语成绩是%lf!\n", (*pstu).num, (*pstu).MathScore, (*pstu).EnlishScore); printf("学号是%d,今年的数学成绩是%.1f, 今年的英语成绩是%lf!\n", pstu->num, pstu->MathScore, pstu->EnlishScore); return 0; }
stu1 = { 12, 66.6,76.5 };
stus[] = { {"Zhou ping", 5, 18, ‘C‘, 145.0}, {"Zhang ping", 4, 19, ‘A‘, 130.5}, {"Liu fang", 1, 18, ‘A‘, 148.5}, {"Cheng ling", 2, 17, ‘F‘, 139.0}, {"Wang ming", 3, 17, ‘B‘, 144.5} };
枚举类型的定义
enum typeName{ valueName1, valueName2, valueName3, ...... };
enum是一个新的关键字,专门用来定义枚举类型,这也是它在C语言中的唯一用途;typeName
是枚举类型的名字;valueName1, valueName2, valueName3, ......
是每个值对应的名字的列表。
enum week{ Mon = 1, Tues = 2, Wed = 3, Thurs = 4, Fri = 5, Sat = 6, Sun = 7 };//依次对week成员赋值;
enum week {a, b, c};//如何没有直接赋值,则从第一个成员为0,后面的成员依次增加;
enum week {a, b=5, c};//前面不变,b=5,后面依次增加;
#include <stdio.h> #include <stdlib.h> typedef enum weekday { mon, tue, wen, tur, fri, sat, sun }Weekday; Weekday test_enum() { Weekday Today = mon; return Today; } int main() { printf("%d\n", test_enum()); //输出0; return 0; }
union data{ int n; char ch; double f; } a, b, c;
标签:char code typename hang mat 数据类型 lib 区别 定义数据
原文地址:https://www.cnblogs.com/aaakihi/p/11520297.html