`
swincle
  • 浏览: 76866 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

C++ Pointers Restrictions

    博客分类:
  • C++
 
阅读更多

指针可以操作两个实体,指针值(地址)和间访值(实体)。

指针常量:指针值不能修改的指针。

常量指针:指向常量的指针。

const int a = 78;
int b = 10;
int c = 18;
const int* ip = &a;  //const修饰指向的实体类型---常量指针
int* const cp = &b;  //const修饰指针*cp----指针常量
int const* dp = &b;  //等价上句---指针常量
const int* const icp = &c //常量指针常量
*ip = 87;  //错,常量指针不能修改指向的常量,*ip只能做右值
ip = &c;  //对,常量指针可以修改指针值
*cp = 81;  //对,指针常量可以修改指向的实体
cp = &b;  //错,指针常量不能修改指针值,即使使用同一地址
*icp = 33;   //错,常量指针常量不能修改指向的常量
icp = &b;  //错,常量指针常量不能修改指针值
int d = *icp; //对
 const只能限定指针的操作,不能限定空间上实体的可改变性。比如上述代码中b,c,d实体可以改变,但不影响指针。
0
1
分享到:
评论

相关推荐

    Using C++11 Smart Pointers

    c++ 11 智能指针详细解释。 清晰版本,非扫描。 c++ 11入门必备

    Understanding.and.Using.C++Pointers(2013.5)].Richard.Reese.文字版.pdf

    Understanding.and.Using.C++Pointers(2013.5)].Richard.Reese.文字版.pdf

    Introduction to C++ Programming Understanding Pointers 无水印pdf

    Introduction to C++ Programming Understanding Pointers 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自...

    C++教程的指针Tutorial on pointers

    C++ Tutorial on pointers

    Functional Programming in C++

    This includes infinite ("lazy") lists, useful higher-order functions (like map, compose, etc.), a reference-counting facility that can be used to replace C++ pointers, many common logical and ...

    Making C++ Objects Persistent: the Hidden Pointers

    pointers. We call such pointers ‘hidden pointers’ because they were not specified by the user. If such C11 objects are made persistent, then these pointers become invalid across program invocations....

    Kenneth Reek - Pointers on C

    The author also endeavors to organize the C code for those who are going on to study C++ and the accompanying object-oriented approach to programming. In addition, he emphasizes how to write C code so...

    Practical C++ Programming C++编程实践

    Simple Pointers const Pointers Pointers and Printing Pointers and Arrays The reinterpret_cast Pointers and Structures Command-Line Arguments Programming Exercises Answers to Chapter Questions Part IV...

    More Effective C++.pdf

    作者 : Scott Meyers 译序、导读 : 侯捷 ...至於大范围主题,例如smart pointers, reference counting, proxy classes,double dispatching, 基本上已属design patterns 的层级! 这些都是经验的累积和心血的结晶。

    Understanding and Using C Pointers 原版pdf by Reese

    language while addressing pointers only to the extent necessary for the topic at hand. Rarely do they venture beyond a basic treatment of pointers and most give only cursory coverage of the important ...

    Linux C++ Programming

    This document provides a comprehensive list of C++ URL pointers, links to C++ online textbooks, and programming tips on C++. This document also provides a C++ library which imitates Java−language, ...

    C++基础教程完整版

    目录 1. 简介 怎样使用本教程 2. C++基础 Basics of C++ 1. C++程序结构 Structure of a program 2. 变量和数据类型 Variables and Data types 3. 常量 Constants ...2、开源工具Dev-C++和wxDev-C++

    C++程序设计教学课件:CHAPTER 7 ARRAYS AND POINTERS.ppt

    C++程序设计教学课件:CHAPTER 7 ARRAYS AND POINTERS.ppt

    Thinking in C: Foundations for Java & C++

    Thinking in C: Foundations for Java & C++ by Chuck Allison produced by Bruce Eckel Chapter 1: Introduction and Getting Started40 MinutesStart Lecture Chapter 2: Fundamental Data Types41 ...

    《C++ for Java Programmers》高清完整英文PDF版

    Chapter topics include philosophy of C++, simplest C++, pointers and reference variables, object-based programming: classes, operator overloading, object-oriented programming: inheritance, templates,...

    C++17 By Example

    The first module will build a library management system that will teach you how to perform efficient file handling and use pointers in your software. To give you a taste of GUI programming, the next ...

    The C++ Standard Library 2nd Edition(高清)pdf

    New smart pointers Regular expressions New STL containers, such as arrays, forward lists, and unordered containers New STL algorithms Tuples Type traits and type utilities The book also examines the ...

    More Effetive c++

    C++ 是一个难学易用的语言! C++ 的难学,不仅在其广博的语法,以及语法背後的...至於大范围主题,例如smart pointers, reference counting, proxy classes,double dispatching, 基本上已属design patterns 的层级!

    More Effective C++中文版

     全面地描述了C++专家所使用的高级技术,包括placement new、virtual constructors、smart pointers、reference counting、proxy classes和double-dispatching等。  以实例说明异常处理带给C++类和函数的冲击。  ...

    c++官方网站标准参考资料

    Distinguish between pointers and references in C++, Comparison of popular compilers and IDEs, Book Of Brilliant Things, Copy constructors, assignment operators, and exception safe assignment, How...

Global site tag (gtag.js) - Google Analytics