首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

简介 const 与 static 的所有用法

2012-11-07 
简介 const 与 static 的全部用法http://blog.csdn.net/newstudent_never/article/details/6381675 const,

简介 const 与 static 的全部用法

http://blog.csdn.net/newstudent_never/article/details/6381675



const,先说变量
const int A; 常量
const int*? pA; 指向常量的指针。 (*pA)++ 错误,不允许改变常量, 但是 pA = &D 可以改变指向的对象。与int* const pA等价
int const? *pA; 常量指针,指向int。(*pA)++ 允许, 但不可以改变指向,既 pA = &D 错误。

与const int? *pA等价

函数?
const int a(); 返回常量
int const * a(); 返回常量指针
const int* a(); 返回指向常量的指针
int a(int b) const; 函数中不允许改变b的值

?

另外还有更多的
const int nB = 10;
const int const * PA = &B;

?


const int const * funA(const int * pBuf) const;
返回指向常量的常指针,函数中(*pBuf)++和pBuf=&D都不允许

?

?

static 静态作用域, 修饰函数中的变量时 说明只赋值一次,并且保留上一次的结果
修饰全局函数或变量时, 说明作用域只针对于这个文件, 与c++中的命名空间 namespace 有点像,
只不过 命名空间可以扩充到多个文件中

热点排行