看例子:

int sloth = 3;

const int *p1 = &sloth;

int * p2 const = &sloth;

这样申明的话,不允许使用p1来修改sloth的值,但是p1可以指向其他的地址;

可以利用p2修改sloth的值,但是p2不允许指向其他地址。

第二个例子:

1、

int gorp = 16;

int chips = 12;

const int *p_snack = &gorp

*p_snack = 20;  (X)

p_snack = &chips;  (√)

注: *p_snack是const而p_snack不是const。

2、

int gorp = 16;

int chips = 12;

int * const p_snack = &gorp;

*p_snack = 20;  (√)

p_snack  = &chips;  (X)

注: p_snack是const而*p_snack不是const。

3、

int gorp = 16;

int chips = 12;

const int * const p_snack = &gorp;

*p_snack = 20;  (X)

p_snack  = &chips;  (X)

注: p_snack和*p_snack都是const。

const int *p 和int * const p 的区别的更多相关文章

  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. (c++) int 转 string,char*,const char*和string的相互转换

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

  5. 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);* ...

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

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

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

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

  8. could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'

    VS2008, 写一个简单的demo的时候出现了这个: 1>------ Build started: Project: GetExportTable, Configuration: Relea ...

  9. const void *a 与 void *const a 的差别

    const void *a 这是定义了一个指针a,a能够指向随意类型的值,但它指向的值必须是常量. 在这样的情况下,我们不能改动被指向的对象,但能够使指针指向其它对象. 比如: const void ...

随机推荐

  1. 用Eclipse导入Maven工程

     步骤一 : 选择 “Import”操作 有两个途径可以选择 “Import”操作; 1>“File”--> "Import..." 2> 在 "Pro ...

  2. GO入门——6. struct与方法

    1 struct Go 中的struct与C中的struct非常相似,并且Go没有class 使用 type struct{} 定义结构,名称遵循可见性规则 支持指向自身的指针类型成员 支持匿名结构, ...

  3. 远程连接服务器或云数据库上的mysql服务 - 赖大大

    主要问题有两种: 1.mysql的权限问题. 2.服务器的防火墙和数据库的安全组没设好的问题. 1.权限问题: 首先登录上mysql mysql> use mysql;      #使用mysq ...

  4. mysql遇见contains nonaggregated column 'information_schema.PROFILING.SEQ'异常

    报错如下:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggrega ...

  5. ContentProvider使用总结

    近日来学习ContentProvider相关的知识,做了一个demo,想和网友分享下. 首先说一点相关的知识: 一:作用 ContentProvider是不同应用程序共享数据的接口,跟共享数据的别的方 ...

  6. IIS 6 配置

    首先想IIS添加asp.net v4.0的应用池.使用管理员身份在cmd窗口输入如下命令 %windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regi ...

  7. Struts2学习(二)———— 表单参数自动封装和参数类型自动转换

    前篇文章对struts2的一个入门,重点是对struts2的架构图有一个大概的了解即可,之后的几篇文章,就是细化struts2,将struts2中的各种功能进行梳理,其实学完之后,对struts2的使 ...

  8. python的Web框架,会话保持及Form表单

    会话 从打开浏览器访问到关闭浏览器,这就是一次会话. cookie 技术 cookie是保存在浏览器的,安全度比较低. # 设置cookie范式,在view中设置 def index(request) ...

  9. set get del

    //设置 $ob = new Redis(); $ob->connect('127.0.0.1', 6379); $re = $ob->set('str1', serialize(['a' ...

  10. cannot import name 'Flask' from 'flask'

    今天发现了智障的真我. 刚入门flask,建了一个文件命名叫flask.py 在virtualenv的容器里运行该py文件,报错cannot import name 'Flask' from 'fla ...