Pointers and Constants

char * const q = "abc"; // q is const
*q = 'c'; // OK
q++; //ERROR
const char *p = "ABCD";
// (*p) is a const char
*p = 'b'; // ERROR! (*p) is the const

在 C++ 是下面这样的。

int i; const int ci = 3;
int * ip; ip = &i; ip = &ci; // Error
const int * cip; cip = &i; cip = &ci;

在 C 语言,下面的代码会有 Warning。ci 的值一直都是 0,但是 *p 的值可以修改。

const int ci = 0;
int *p = &ci;
printf("&ci = %p\n", &ci);
printf(" p = %p\n", p);
*p = 2;
printf("*p = %d\n", *p);
printf("ci = %d\n", ci);

Pointers and Constants的更多相关文章

  1. function 的声明

    <?php function test() { echo "abc"; } test(); ?> 结论: 一 编译 a.对 函数声明进行词法分析和语法分析:在语法分析中 ...

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

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

  3. C++_class_powerpoint_1.1

    Types and Declarations Boolean Type bool type – boolean , logic type bool literal – true, falseint a ...

  4. Constants in C++

    The first motivation for const seems to have been to eliminate the use of preprocessor #define for v ...

  5. Leetcode 笔记 117 - Populating Next Right Pointers in Each Node II

    题目链接:Populating Next Right Pointers in Each Node II | LeetCode OJ Follow up for problem "Popula ...

  6. Leetcode 笔记 116 - Populating Next Right Pointers in Each Node

    题目链接:Populating Next Right Pointers in Each Node | LeetCode OJ Given a binary tree struct TreeLinkNo ...

  7. some OpenGL constants

    some OpenGL constants This is from (https://github.com/peterderivaz/pyopengles/blob/master/gl2.py) G ...

  8. [LeetCode] Populating Next Right Pointers in Each Node II 每个节点的右向指针之二

    Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...

  9. [LeetCode] Populating Next Right Pointers in Each Node 每个节点的右向指针

    Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...

随机推荐

  1. Beats:使用Elastic Stack对Nginx Web服务器监控

  2. firewalld教程

    修改配置 cat firewalld.conf | grep -Ev "^#|^$" DefaultZone=trusted #主要是这个位置,必须修改trusted的 Minim ...

  3. 不能获取到镜像,ImagePullBackoff或者Pending

    Pending 应用长时间处于 Pending 状态时,也可以按照这个办法查看镜像的下载进度. 安装 Kubernetes 过程中,或者向 Kubernetes 部署应用的过程中,有可能会碰到 Ima ...

  4. 研发效能之技术治理&技术治理架构师

    最近很多公司专门设置了一个职位叫「技术治理架构师」,主要负责公司技术治理相关事宜.这是个非常有意思的职位.技术治理的活,之前我们也是做的,只是没有提的这么明确,一般都是研发效能团队.PMO.架构团队. ...

  5. 数据火器库八卦系列之瑞士军刀随APP携带的SQLite

    来源:云数据库技术 数据库打工仔喃喃自语的八卦历史 1. 为导弹巡洋舰设计,用在手机上的数据库 2. Small and Simple, and Better 3. 如何看出是自己的娃:产品定位,特点 ...

  6. Codeforces Round #823 (Div. 2) A-D

    比赛链接 A 题解 知识点:贪心. 对于一个轨道,要么一次性清理,要么一个一个清理.显然,如果行星个数大于直接清理的花费,那么选择直接清理,否则一个一个清理.即 \(\sum \min (c,cnt[ ...

  7. linux基础总结

    linux的特点 - 免费的/开源       - 支持多线程/多用户       - 安全性好       - 对内存和文件管理优越 关机命令      shutdown -h now(立即进行关机 ...

  8. Idea运行支付宝网站支付demo踩坑解决及其测试注意事项

    一.前言 在一些商城网上中,必不可少的是支付,支付宝和微信比较常见,最近小编也是在研究这一块,看看支付宝怎么进行支付的,支付宝给我们提供了demo和沙箱测试.减少我们的申请的麻烦,公钥和秘钥也比之前方 ...

  9. Java学习之路:快捷键

    常用的快捷键 Ctrl+Shift:切换输入法 Ctrl+C:复制 Ctrl+V:粘贴 Ctrl+X:剪切 Ctrl+A:全选 Ctrl+Z:撤销 Ctrl+Y:返回撤销 Ctrl+S:保存 Shif ...

  10. Java云原生崛起微服务框架Quarkus入门实践

    @ 目录 概述 定义 GraalVM简介 为何使用 特性 官方性能 实战 入门示例 步骤 安装GraalVM 创建quarkus工程 Idea导入项目 Idea运行和调试 打包成普通的Jar 打包成依 ...