C语言32关键字以及const、static、typedef、struct、union、enum用法

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:说明变量在程序执行中可被隐含地改变

const作用

static作用

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值