1.关键字不可以自创
2.变量名也不能与关键字同名
3.关键字
(1.)
auto :每个局部变量都由auto修饰(一般省略)
int main ()
{ int a = 10;}
a进入{ 自动生成,出 } 自动销毁,所以a是自动的变量
(2.)
break 循环语句 ,switch语句
case switch语句
switch 语句
(3.)
const 常变量
double 双精度 float 单精度
int 整型 long 长整型 short 短整型
char 字符
(4.)
continue 继续 default 默认
(5.)
do 在do while 循环;
for for循环;
while while循环;
if else 选择语句
(6.)
extern 申明外部符号 在同一工程下,在一个文件中引用另一个文件中的变量时,要在该变量前加上extern
(7.)
goto goto语句
(8.)
register 寄存器关键字(建议编译器将register后的变量存放到寄存器中)
(9.)
enum 枚举
(10.)
return 返回值
(11.)
signed 有符号——unsigned 无符号的
(12.)
sizeof 求大小
(13.)
static 静态的
static修饰局部变量
void test()
{
int a=1;
a++;
printf("%d\n",a);
}
int main()
{
int i=0;
while(i<10)
{
test();
i++;
}
return 0;
}
上述代码输出十个2,十次循环进行十次test函数,a是局部变量每次进行test函数时,a都是1所以每次输出都是2。
当定义 static int a=1 时,输出为2345678910.
static修饰局部变量,本质上改变了变量的存储类型,结果表现在生命周期改变(与全局变量一样)
static修饰全局变量
static修饰的全局变量无法被同一工程下的其他文件引用,只能在自己所在的源文件内部使用。
static修饰函数
文件一:
int add(intx,inty)
{
return x+y;
}
文件二:
extern int add(intx,inty)
int main()
{
int a=10;
int b=10;
int sum=add(a,b);
printf("sum=%d\n",sum);
return 0;
}
与全局变量差不多,未被static修饰的函数可以被引用,而变成 static int add(int x,int y)后,无法被引用
(14.)
struct 结构体
(15.)
typedef 类型定义(类型重命名)
typedef unsigned int u_int;
int main()
{
unsigned int num;
u_int num2;
return 0
}
unsigned int =u_int 别名
(16.)
union 联合体,公用体
(17.)
void 空
(18.)
volatile
#:define include 不是关键字