Some people may be confused about the sequence of const and * on declaration in C++/C, me too.

  Now I think we can distinguish them by this way:

  1.only noticing the position of const to *, and we can find that the following statements are same:    

  1. const int * foo_int;
  2. int const * foo_int_;  //same.

  2.regarding const as a postpositive attributes,and you will know the content which is const.

  

  1. int foo = ;
  2. int foo_ = ;
  3.  
  4. //the foo_int is const, but the pointer to foo_int can be chaged.
  5. int const * foo_int = &foo;
  6.  
  7. //illegal, the value cannot be chaged
  8. //*foo_int = 7
  9.  
  10. //okay!
  11. foo_int = &foo_;
  12.  
  13. //the pointer to int is const, but foo_int_ can be chaged.
  14. int * const foo_int_ = &foo_int;
  15.  
  16. //illegal, the pointer cannot be changed.
  17. //foo_int = &foo_int_;
  18. //even if the new pointer is same, it's illegal
  19. //foo_int = &foo_int;
  20.  
  21. //okay
  22. *foo_int = ;

the difference between const int *, int * const, int const *的更多相关文章

  1. const int * p 和 int const * p 和 int * const p 的区别

    首先注意,const int * p 和int const *p 是一样的,并且不管是不是*p,即使const int i和int const i也是一样的,所以我们接下来只讨论int const * ...

  2. const int *p与int *const p的区别(转:csdn,suer0101)

    本文只是一篇学习笔记,是看了<彻底搞定C指针>中的相关篇幅后的一点总结,仅此而已! 一.先搞清const int *p与int const *p的区别 它们的区别就是:没有区别!! 无论谁 ...

  3. C++ char*,const char*,string,int 的相互转换

    C++ char*,const char*,string,int 的相互转换   1. string转const char* string s ="abc";const char* ...

  4. const int *p 和int * const p 的区别

    看例子: int sloth = 3; const int *p1 = &sloth; int * p2 const = &sloth; 这样申明的话,不允许使用p1来修改sloth的 ...

  5. (c++) int 转 string,char*,const char*和string的相互转换

    一.int 和string的相互转换 1 int 转化为 string c++ //char *itoa( int value, char *string,int radix); // 原型说明: / ...

  6. error C2556: 'const char &MyString::operator [](int)' : overloaded function differs only by return type from 'char &MyString::operator [](int)'

    char & operator[](int i);const char & operator[](int i);/*const char & operator(int i);* ...

  7. [转] const int *a与int *const a,const int *const a的区别

    http://blog.csdn.net/zhangheng837964767/article/details/33783511 关键问题点:const 属于修饰符 ,关键是看const 修饰的位置在 ...

  8. const int *a与int *const a,const int *const a的区别

    来源:https://blog.csdn.net/zhangheng837964767/article/details/33783511 关键问题点:const 属于修饰符 ,关键是看const 修饰 ...

  9. what is difference in (int)a,(int&)a,&a,int(&a) ?

    This interview question come from a famous communication firm of china. : ) #include <iostream> ...

  10. C++中 int i 与 int &i 注意事项

    来源:http://blog.csdn.net/qianchenglenger/article/details/16949689 1.int i 传值,int & i 传引用 int i不会回 ...

随机推荐

  1. 004-For与Function进阶实战、Lazy的使用

    004-For与Function进阶实战.Lazy的使用 For进阶 非常常见的形式 可以加入条件表达式进行数据过滤 Function进阶 函数是有值的(默认的话为Unit),所以可以直接将结果赋值给 ...

  2. 作业七:团队项目——Alpha版本冲刺阶段003

    今日进展:我们的目标是做一款扫雷游戏,所以我们先去玩了几款游戏,找到了扫雷游戏的一些特点. 今日安排:先进行了一些必要的游戏过程,进行了基本的扫雷界面规划.

  3. Android高效加载大图、多图解决方案,有效避免程序OOM

    高效加载大图片 我们在编写Android程序的时候经常要用到许多图片,不同图片总是会有不同的形状.不同的大小,但在大多数情况下,这些图片都会大于我们程序所需要的大小.比如说系统图片库里展示的图片大都是 ...

  4. WPF环境下多点触屏开发的一些经验(转)

    本系列将介绍Multi-Touch(MT)多点触控技术的相关内容,使开发人员了解如何在Windows 平台中开发出具有MT 功能的应用程序.众所周知Windows 7 操作系统自身已经支持具有MT 功 ...

  5. 记录Js

    1.对于js,没有系统的学习.有要经常的用到,每次都是百度查找,为了以后能查询. (1). $(function () { $('.restbtn').on("click", fu ...

  6. 解决MySQL数据库不允许从远程访问的方法

    授权法.例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话. mysql>GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' ...

  7. 关于ssh调用远程后台命令挂住的解释

    目前看到的最详细最全面的解释: http://www.snailbook.com/faq/background-jobs.auto.html

  8. redis主从复制搭建

    1. 安装redis-2.4.6-setup-32-bit.exe 2. 打开一个cmd窗口,使用cd命令切换到指定目录(F:\Redis) 运行 redis-server.exe redis.con ...

  9. NSOperation基本概念

    NSOperation的作用 配合使用NSOperation和NSOperationQueue也能实现多线程编程   NSOperation和NSOperationQueue实现多线程的具体步骤 先将 ...

  10. 错误:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

    我们在利用Eclipse进行Java web开发时,可能会出现这样的错误:The superclass javax.servlet.http.HttpServlet was not found on ...