关键字typedef、static的使用

您所在的位置:网站首页 typedef与struct连用 关键字typedef、static的使用

关键字typedef、static的使用

2024-07-12 11:28| 来源: 网络整理| 查看: 265

文章目录 c语言中的关键字关键字的特点typedef关键字的使用static关键字的作用static修饰局部变量内存中存储空间的分配static修饰全局变量static修饰函数

c语言中的关键字

在89/90的第一版c语言中,c语言的关键字有32个 如下

auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while

关键字的特点

1、c语言提供的,不能自己创建关键字

2、变量名不能是关键字,下面这种就是错误的写法

typedef关键字的使用

作用:类型定义/类型重定义

当我们使用unsigned int来定义变量的时候,可能会因为它太长了导致难写,所以我们用typedef来重新定义unsigned int,使得定义简略

下面的unsigned int和u_int意思一样

#include typedef unsigned int u_int;//将unsigned int重定义为u_int int main() { unsigned int num = 100; u_int num = 100;//这里的两个定义的类型都是一样的,只不过名字发生了变化 return 0; } static关键字的作用 static修饰局部变量 void test() { int a = 0;//进函数存在,出函数被销毁 a++; printf("%d",a); } int main() { int i = 0; while(i


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3