本文共 993 字,大约阅读时间需要 3 分钟。
enum WeekDay {
Monday=0,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday
};
main() {
enum WeekDay day = Sunday;
printf("%d\n",day);
system("pause");
}
枚举中的值是递增的。
枚举默认是从0开始
声明自定义数据类型,配合各种原有数据类型来达到简化编程的目的的类型定义关键字。
在计算机编程语言中用来为复杂的声明定义简单的别名;
#include <stdio.h>
#include <stdlib.h>
typedef int i;
typedef long l;
main() {
i m = 10;
l n = 123123123;
printf("%d\n", m);
printf("%ld\n", n);
system("pause");
}
#include<stdio.h>
#include<stdlib.h>
/**
结构体指针
*/
//定义一个结构体
struct Student{
int age;
float score;
char sex;
}
main()
{ //结构体
struct Student stu = {20,88.5,'W'};
printf("stu.age=%d\n",stu.age);
//结构体指针
struct Student* stuPoint;
//赋地址值
stuPoint = &stu;
//取值 (*stuPoint).age
printf("(*stuPoint).age=%d\n",(*stuPoint).age);
//赋值 (*stuPoint).age =80;
//另外一种取值 (*stuPoint).等价于 stuPoint-> 例如:
//(*stuPoint).age 等价于 stuPoint->age
printf("stuPoint->age=%d\n",stuPoint->age);
system("pause");
}
运行结构如下:
(*stuPoint).age 等价于 stuPoint->age
本教程由尚硅谷教育大数据研究院出品,如需转载请注明来源。