const与static归纳总结
来源:互联网 发布:金蝶erp软件二次开发 编辑:程序博客网 时间:2024/05/14 05:59
static与const都是C语言中的关键字,他们都可以修饰变量,函数等。
1.const
const与 变量
int x = 5; // 变量
const int x = 5;//在c++中,x是常量,在c语言中,x是不可改变的变量
const与指针类型
我们用图来表示各种指向关系。
注:图中给出的地址是假设的,并非真实地址。~~
(一)const与一级指针
eg:
第2句语句是说,pa指向的内容是不可改变,第3句语句改变了pa指向的内容,所以,以上代码不正确。const 修饰pa,所以,pa的内容不可改变,就是里边只能存a的地址,语句3改变了pa的内容,所以以上代码不对。(二)const与二级指针
eg:
ppa不能改变,里边只能存放pa的地址。语句3,ppa指向b的地址,语句4是将ppa指向的b的地址的内容改为30,。并未改变ppa,所以以上程序正确。eg:ppa的指向即*ppa不可改变,第2语句改变ppa的指向,错误。
eg:ppa的指向的指向不可改变,错误。
const 与引用
int x = 3;
const int &y = x;
y = 5;//错误
2.static
(1)static修饰函数:这个函数只能在当前的.c文件可见,这样就可以在不同的.c文件中定义同名函数,而不引起冲突,只要其中一个函数用static修饰;
(2)static修饰局部变量:static变量定义在一个函数内,只有这个函数可以读取它,它的值在程序执行时一直保持;
(3)static修饰全局变量:ststic变量定义在一个文件中,只有这个文件可以读取它。
下边我们来看一道例题:
0 0
- const与static归纳总结
- const与static归纳总结
- const,static关键字用法归纳
- const static 与static const const static
- static 与 const 的作用总结
- static 与 const 的作用总结
- static 与static const
- const static总结
- const和static总结
- static、const总结
- const static 与static const的使用
- const static 与static const的使用
- const 与 static
- static const与#define
- Static与Const
- static与const小结
- const,typedef与static
- static 与 const
- android 实现和手机home键一样的功能。
- Android M权限管理(续)
- hdu 6030 (矩阵快速幂)
- 关于const
- ReactiveCocoa入门教程:第一部分
- const与static归纳总结
- HDU 6024 Building Shops
- TransitionDrawable一个能渐变显示的Drawable
- Spring IOC之通过JAVA代码配置Bean
- PAT 乙级 1034. 有理数四则运算(20)
- 自己做游戏(一)-PhotonServer配置
- centos 安装Theano详细教程
- android中关于keystore的两篇文章
- java反射