经常忘记,保存一下..

#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
int a=;
int b; /*定义指向const的指针(指针指向的内容不能被修改)*/
const int* p1;
int const* p2; /*定义const指针(由于指针本身的值不能改变所以必须得初始化)*/
int* const p3=&a; /*指针本身和它指向的内容都是不能被改变的所以也得初始化*/
const int* const p4=&a;
int const* const p5=&b; p1=p2=&a; //正确
*p1=*p2=; //不正确(指针指向的内容不能被修改) *p3=; //正确
p3=p1; //不正确(指针本身的值不能改变) p4=p5;//不正确 (指针本身和它指向的内容都是不能被改变)
*p4=*p5=; //不正确(指针本身和它指向的内容都是不能被改变) return ;
}

引用地址: http://hi.baidu.com/study_cs/item/c4c469cb35bd890bac092f37

[转]const指针与指向const的指针的更多相关文章

  1. 不可或缺 Windows Native (18) - C++: this 指针, 对象数组, 对象和指针, const 对象, const 指针和指向 const 对象的指针, const 对象的引用

    [源码下载] 不可或缺 Windows Native (18) - C++: this 指针, 对象数组, 对象和指针, const 对象,  const 指针和指向 const 对象的指针, con ...

  2. const 指针与指向const的指针

    最近在复习C++,指针这块真的是重难点,很久了也没有去理会,今晚好好总结一下const指针,好久没有写过博客了,记录一下~ const指针的定义: const指针是指针变量的值一经初始化,就不可以改变 ...

  3. const指针和指向常量的指针

    先看下面六种写法: . const int p; . const int *p; . int const* p; . int * const p; . const int * const p; . i ...

  4. Const指针 、 指向const的指针 、引用、指针

    1. const指针和 指向const的指针 指向const的指针: 不允许通过指针来改变其指向的const值 const double *cptr *cptr = 42;  // error! 指针 ...

  5. 辨析 const指针 和 指向常量的指针

    辨析以下几种指针p的定义. ; int *p = &tmp; const int *p = &tmp; int const* p = &tmp; int * const p = ...

  6. 【转】const int *p和int * const p的区别(常量指针与指向常量的指针)

    [转]作者:xwdreamer   出处:http://www.cnblogs.com/xwdreamer 对于指针和常量,有以下三种形式都是正确的: const char * myPtr = &am ...

  7. const对象,指向const对象的指针 和 const 指针

    const对象: const对象声明时必须赋初值,该值在编译阶段确定,不可在程序中修改. const修饰符既可放在类型名前也可放在类型名后,通常放在类型名前.不过放在类型名后易于理解. const i ...

  8. const指针和指向const的指针

    int *const p=&a; 这是const指针,这种指针必须在定义时就给出它所指向的地址,否则会error:uninitialized const 'p'.const指针的指针本身是co ...

  9. 速记const 指针与指向const的指针

    指向const的指针.它的意思是指针指向的内容是不能被改动的.它有两种写法. ` const int* p; (推荐) int const* p;` 再说const指针.它的意思是指针本身的值是不能被 ...

随机推荐

  1. zoj Burn the Linked Camp (查分约束)

    Burn the Linked Camp Time Limit: 2 Seconds      Memory Limit: 65536 KB It is well known that, in the ...

  2. 2.3多线程(java学习笔记)synchronized关键字

    一.为什么要用synchronized关键字 首先多线程中多个线程运行面临共享数据同步的问题. 多线程正常使用共享数据时需要经过以下步骤: 1.线程A从共享数据区中复制出数据副本,然后处理. 2.线程 ...

  3. iOS禁止多点操作(按钮和Table项)

    1)避免同时点击多个按钮: [btn setExclusiveTouch:YES]; 设置确保当btn点击时,其他按钮不响应: (2)避免同时点击UITableView中多个row -(NSIndex ...

  4. Vue.js 2.0源码解析之前端渲染篇

    一.前言 Vue.js框架是目前比较火的MVVM框架之一,简单易上手的学习曲线,友好的官方文档,配套的构建工具,让Vue.js在2016大放异彩,大有赶超React之势.前不久Vue.js 2.0正式 ...

  5. kubernetes1.5.2--部署node-problem-detector服务

    本文基于kubernetes 1.5.2版本编写 node经常会遇到以下问题: 硬件问题: cpu 内存 磁盘 内核问题: 内核死锁, 文件系统损坏 容器问题: 守护进程无响应 K8S集群管理对nod ...

  6. 设计模式之桥接模式(php实现)

    github地址:https://github.com/ZQCard/design_pattern /** * 桥接模式 * 优点: * 1.分离抽象接口及其实现部分.提高了比继承更好的解决方案. * ...

  7. VS快捷键说明

    转载:http://blog.csdn.net/tianzhaixing2013/article/details/51811608 Ctrl+E,D —-格式化全部代码 Ctrl+E,F —-格式化选 ...

  8. ansible自动化工具使用

    1.服务端配置 安装即可,无需启动,在安装ansible之前需要配置epel源 [root@m01 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirr ...

  9. 【转】docker安装PostgreSQL

    原文:https://blog.csdn.net/liuyueyi1995/article/details/61204205 你先确认这两件事:1)执行 docker exec -it dream.p ...

  10. 2017.4.10 spring-ldap官方文档学习

    官网:http://www.springframework.org/ldap 官方文档及例子(重要):http://docs.spring.io/spring-ldap/docs/2.1.0.RELE ...