当前位置:网站首页>c语言中的几个关键字
c语言中的几个关键字
2022-07-02 05:47:00 【Croxd】
auto:自动局部变量,一般我们在定义局部变量的时候,就是auto局部变量,只不过我们写的时候把它省略掉也是一样的效果的,局部变量是保存在栈上的。
extern:生命全局变量的。比如我 a.c中定义可 int a, b.c中想调用 这个a 但是没有定义,这时候在b.c中你要使用这个a变量之前,用extern a,来告诉a是在别的文件定义了,就可以使用了。
static:有两种用法,第一种是修饰局部变量,叫做静态局部变量。静态局部变量跟赋值了的全局变量一样,保存在数据段,生命周期是一样的。他的连接是无连接的。
第二种是修饰全局变量或者修饰函数,它是把外链接变成内连接属性,只能在本文件中使用,不想被其他文件调用。外连接属性是普通的函数和全局变量,无连接属性是局部变量和静态局部变量。
register:一般用来修饰经常被调用到的全局变量。会把它放在寄存器中,的比如uboot中的 gd 全局变量,这样的好处可以提高效率。但是他是尽量放到寄存器里面,而不是一定会放到寄存器里面。
volatile:可变的,易变的。有三种情况变量的值是无法知晓的,1.中断改变的值,2.多线程中用的同一变量,3.硬件改变的值(寄存器),这三种编译器都是无法知道值的改变。所以用来告诉编译器遇到这个变量的时,不要优化这个变量。这样就不会出现错误。
const:常用来定义常量,表示这个常量是不可以被修改的。主要看 const 后面和哪个最近,就是修饰哪个,靠近* 就是值不可被修改,靠近变量就是地址是不可被修改的。
- const int * a:常量指针,值不可以修改,指向的地址可以修改。
- int * const a:指针常量,值可以修改,指向的地址不可以修改。
边栏推荐
猜你喜欢

How to write good code - Defensive Programming Guide

Lingyunguang rushes to the scientific innovation board: the annual accounts receivable reaches 800million. Dachen and Xiaomi are shareholders

Gee series: unit 6 building various remote sensing indexes in Google Earth engine

Principle and implementation of parallax effect

Conglin environmental protection rushes to the scientific and Technological Innovation Board: it plans to raise 2billion yuan, with an annual profit of more than 200million yuan

MySQL foundation --- query (learn MySQL foundation in 1 day)

Detailed explanation of Pointer use

Balsamiq wireframes free installation

Huawei Hongmeng OS, is it OK?

centos8安裝mysql8.0.22教程
随机推荐
Ls1046nfs mount file system
1037 Magic Coupon
VSCode paste image插件保存图片路径设置
Fabric. JS three methods of changing pictures (including changing pictures in the group and caching)
centos8安裝mysql8.0.22教程
ERP management system development and design existing source code
1036 Boys vs Girls
Résumé de la collection de plug - ins couramment utilisée dans les outils de développement idea
Cube magique infini "simple"
mysql的约束总结
软件测试基础篇
I want to understand the swift code before I learn it. I understand it
Alibaba: open source and self-developed liquid cooling data center technology
Installation du tutoriel MySQL 8.0.22 par centos8
all3dp.com网站中全部Arduino项目(2022.7.1)
Generate QR code
Visual Studio导入
Zzuli:1061 sequential output of digits
Here comes a new chapter in the series of data conversion when exporting with easyexcel!
金融门户相关信息