`
swincle
  • 浏览: 78055 次
  • 性别: 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
分享到:
评论

相关推荐

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

    本书《Understanding and Using C++ Pointers》由 Richard Reese 编写,旨在帮助读者全面了解 C++ 指针的概念及其在实际编程中的应用。通过本书的学习,读者将能够掌握指针的基础知识,理解如何声明和使用指针,以及如何...

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

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

    C++设计新思维_C++_

    7. 轻量级智能指针(smart pointers):如`std::unique_ptr` 和 `std::shared_ptr`,它们是C++11引入的,用于管理对象的生命周期,防止内存泄漏,是现代C++编程中资源管理的重要工具。 8. 设计原则:C++设计新思维...

    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...

    C++/CLI教程

    7. 指针和引用(Pointers and References):在C++/CLI中,指针和引用的使用与传统C++有所不同。例如,托管代码中使用指针时需要考虑垃圾回收的影响,而引用则是一个保留字,用于访问托管对象。 8. 包含规则(Rules...

    C++标准库(第二版) 学习C++11的好书

    4. **类型安全的指针(Smart Pointers)**:C++11引入了`std::unique_ptr`, `std::shared_ptr`和`std::weak_ptr`等智能指针,以替代原始指针,自动管理内存,防止内存泄漏。 5. **并发编程支持(Concurrency ...

    Making C++ Objects Persistent: the Hidden Pointers

    ### 关于C++对象持久化中的隐藏指针问题 #### 概述 本文探讨了C++(文中误写为C11,实际应为C++)中对象持久化时遇到的一个核心问题:隐藏指针的存在及其对持久化的挑战。文章首先介绍了隐藏指针的基本概念,然后...

    C++教程的指针Tutorial on pointers

    本教程的"Basic Tutorial on Pointers.chm"文件应该包含了更详细的内容,涵盖了指针的更多高级主题,如指针数组、指针作为函数返回值、指针与引用等。学习并熟练掌握这些知识将极大地提升你的C++编程能力。在实际...

    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 ...

    More Effective C++中文版

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

    Chapter 4- Arrays Pointers and String.rar_C++_filmhfx

    在C++编程语言中,数组、指针和字符串是核心概念,它们在程序设计中扮演着至关重要的角色。本章“Chapter 4- Arrays Pointers and String”将深入探讨这些主题,尤其对于电影制作(filmhfx)领域的编程工作更是至关...

    C++第五期C++

    C++提供了多种工具来帮助开发者管理内存,如智能指针(Smart Pointers)。这一期可能会详细介绍std::shared_ptr、std::unique_ptr等智能指针类型的工作原理及其应用场景,从而帮助开发者避免常见的内存泄漏问题。 #...

    电子书 深入理解C++11(PDF)

    6. **智能指针(Smart Pointers)**:C++11标准库提供了三种智能指针:`std::unique_ptr`、`std::shared_ptr`和`std::weak_ptr`,它们自动管理内存,避免了传统的指针可能导致的内存泄漏问题。 7. **多线程支持(std::...

    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++20标准手册.rar

    5. **原子智能指针(Atomic smart pointers)**:C++20为`std::unique_ptr`和`std::shared_ptr`添加了原子操作,使得在多线程环境中无锁管理智能指针成为可能,提升了并发安全。 6. **强类型枚举(Strongly-typed ...

    C/C++11-20的标准API中文帮助文档CHM

    10. **智能指针(Smart Pointers)**:如`std::unique_ptr`、`std::shared_ptr`和`std::weak_ptr`,提供了自动内存管理的解决方案,防止内存泄漏。 C++14和C++17标准进一步扩展和完善了这些特性,并引入了一些新的...

    C++基础教学PPT

    此外,为了成为一名熟练的C++开发者,还需要掌握内存管理,包括指针操作、动态内存分配和释放,以及智能指针(Smart Pointers)的使用,它们可以防止内存泄漏并简化资源管理。同时,了解并实践良好的编程实践,如...

    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 ...

Global site tag (gtag.js) - Google Analytics