const和指针结合使用的例子
2014-06-09 15:19
253 查看
刚开始看《Effective C++》这本书,里面讲到const。我按照书上讲的,简单的写了个例子。如下。备忘。
#include <stdio.h> int main() { /* //下面const的用法表示const修饰的是p所指向的值是常量 int i = 10; int k = 20; const int *p = &i; printf("%x\n",p); //*p = 20; //这一句是错误的,*p所指向的值是常量 p = &k; printf("%x\n",p); printf("%d",*p); */ //下面演示const修饰指针本身的情况 int m = 100; int n = 200; char * const p = (char * const)&m; //如果不加(char * const)会提示错误 printf("%x\n",p); printf("%d\n",*p); //p = (char * const)&n; //提示错误,不能给常量p赋值 *p = 50; printf("%x\n",p); printf("%d\n",*p); getchar(); return 0; }
相关文章推荐
- 关于c++中const和指针结合的使用
- const 和一级指针、二级指针、引用的结合使用总结
- AcceptEx函数与完成端口的结合使用例子
- appfuse例子一步步解析!结合eclipse3.0一起使用
- 关于const与指针搭配使用的一点记录
- popen 使用例子 c与sh,管道的结合使用
- 关于指针中使用const
- 对收藏夹中AspectJ和Spring结合使用例子(What the teacher said (using AspectJ with Spring part II). )的补充
- C语言 const 指针使用技巧之——返回指针的函数
- C语言技巧--在结构体中使用函数例子(定义一个指向函数的指针)
- SqlServer 多条件查询 [存储过程] 经典例子结合C#的使用
- 使用XMLHttpRequest结合struts2实现Ajax异步调用的例子
- 函数对象 与 count_if()结合使用 例子
- C++ const 限定符 指针的使用方法
- 需要注意的地方 - const 和typedef的结合使用
- C++ 浅谈指针的用法:与const、一维数组、二维数组、typedef等结合
- appfuse例子一步步解析!结合eclipse3.0一起使用
- const的指针的使用
- c++ const和指针复合使用说明
- C 语言中 const,指针,数组例子