大家好,欢迎来到IT知识分享网。
常见关键字
一、常见关键字
C语言提供关键字,不能自己创建;
变量名不能是关键字;
define,include不是关键字,而是预处理命令
1.关键字 auto
每个局部变量都是auto修饰的,只不过省略了。
2.关键字 extern
是用来声明外部符号的
3.关键字register
寄存器关键字
register int num = 100; //建议num的值寄放在寄存器中
4.关键字 signed
有符号
5.关键字 unsigned
无符号
6.关键字 union
联合体(公用体)
7.关键字 void
无、空
8.关键字 typedef
typedef 顾名思义是类型定义,这里应该理解为类型重命名。
//将unsigned int 重命名为uint_32, 所以uint_32也是一个类型名 typedef unsigned int uint_32; int main() {
//观察num1和num2,这两个变量的类型是一样的 unsigned int num1 = 0; uint_32 num2 = 0; return 0; }
9.关键字static
- 修饰局部变量-称为静态局部变量
- 修饰全局变量-称为静态全局变量
- 修饰函数-称为静态函数
修饰局部变量
#include <stdio.h> void test() {
int i = 1; i++; printf("%d ", i); } int main() {
int i = 0; for(i=0; i<10; i++) {
test(); } return 0; }
#include <stdio.h> void test() {
//static修饰局部变量 static int i = 1; i++; printf("%d ", i); } int main() {
int i = 0; for (i = 0; i < 10; i++) {
test(); } return 0; }
修饰全局变量
#include<stdio.h> //add.c int g_val = 2018; //test.c int main() {
printf("%d\n", g_val); return 0; }
#include<stdio.h> //代码2 //add.c static int g_val = 2018; //test.c int main() {
printf("%d\n", g_val); return 0; }
修饰函数
#include<stdio.h> //代码1 //add.c int Add(int x, int y) {
return c+y; } //test.c int main() {
printf("%d\n", Add(2, 3)); return 0;
#include<stdio.h> //代码2 //add.c static int Add(int x, int y) {
return c+y; } //test.c int main() {
printf("%d\n", Add(2, 3)); return 0; }
本质上,static是将函数的外部链接属性变成了内部链接属性,与static修饰全局变量一样。
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/111512.html







