32个关键子
1 数据类型关键字(12个):
(1) char :声明字符型变量或函数
(2) double :声明双精度变量或函数
(3) enum :声明枚举类型
(4) float:声明浮点型变量或函数
(5) int: 声明整型变量或函数
(6) long :声明长整型变量或函数
(7) short :声明短整型变量或函数
(8) signed:声明有符号类型变量或函数
(9) struct:声明结构体变量或函数
(10) union:声明联合数据类型
(11) unsigned:声明无符号类型变量或函数
(12) void :声明函数无返回值或无参数,声明无类型指针(基本上就这三个作用)
2 控制语句关键字(12个):
A循环语句
(1) for:一种循环语句(可意会不可言传)
(2) do :循环语句的循环体
(3) while :循环语句的循环条件
(4) break:跳出当前循环
(5) continue:结束当前循环,开始下一轮循环
B条件语句
(1)if: 条件语句
(2)else :条件语句否定分支(与 if 连用)
(3)goto:无条件跳转语句
C开关语句
(1)switch :用于开关语句
(2)case:开关语句分支
(3)default:开关语句中的“其他”分支
D return :子程序返回一个值
3 存储类型关键字(4个)
(1)auto :声明自动变量 一般不使用
(2)extern:声明在其他文件中定义的变量
(3)register:声明积存器变量
(4)static :声明静态变量
4 其它关键字(4个):
(1)const :声明只读变量
(2)sizeof:计算数据类型长度,是个运算符
(3)typedef:用以给数据类型取别名
(4)volatile:说明变量在程序执行中可被隐含地改变
typedef、struct、union、enum用法
#include<stdio.h>
void func_enum(void)
{
typedef enum
{
test1,
test2,
test3,
test4,
test5,
test6,
test7
}TEST;
TEST t = test2; //只能为test1--test7
printf("t: %d %lu \n", t, sizeof(TEST));
}
void func_union(void)
{
typedef struct _Str_D
{
int tmp1;
char ch1;
union{
struct{
int tmp2;
}str1;
struct{
short tmp3;
char ch2;
char ch3;
}str2;
}un1;
}str_d;
str_d str = {};
str.tmp1 = 1;
str.ch1 = 1;
#if 1
str.un1.str1.tmp2 = 1;
#else
str.un1.str2.tmp3 = 1;
str.un1.str2.ch2 = 1;
str.un1.str2.ch3 = 1;
#endif
printf("union: %lu \n", sizeof(str));
}
int main()
{
func_enum();
func_union();
return 0;
}
结果
t: 1 4
union: 12