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. Traefik 控制面板 SaaS 服务 Pilot

    文章转载自:https://mp.weixin.qq.com/s?__biz=MzU4MjQ0MTU4Ng==&mid=2247485572&idx=1&sn=8ffa2bc7 ...

  2. prometheus告警规则模板:MySQL,nginx,node

    rules_up.yml groups: - name: up rules: - alert: mysql expr: up{instance="db1",job="my ...

  3. EFK-5: ES集群开启用户认证

    转载自:https://mp.weixin.qq.com/s?__biz=MzUyNzk0NTI4MQ==&mid=2247483826&idx=1&sn=583e9a5260 ...

  4. Elasticsearch与MySQL对应关系表

    MySQL 中的数据库(DataBase),等价于 ES 中的索引(Index). MySQL 中一个数据库下面有 N 张表(Table),等价于1个索引 Index 下面有 N 多类型(Type). ...

  5. Nginx缓存了DNS解析造成后端不通--代理

    文章转载自:https://segmentfault.com/a/1190000022365954 1 问题现象 我们使用 Nginx 的时候,经常会用到 Proxy 功能,为了方便管理,后端站点或者 ...

  6. windows bat文件设置环境变量

    主要是SET和SETX这个两个命令 SETX 永久设置用户环境变量 SETX /M 永久设置系统环境变量 SET 临时设置用户环境变量 SET /M 临时设置系统环境变量

  7. prometheus设置使用密码nginx反向代理访问

    注意: 1.设置访问密码的方式 2.ngixn反向代理的配置 # 安装 Apache工具包 apt install apache2-utils htpasswd -bc /etc/nginx/.pro ...

  8. 5G 与数字化转型的关系是怎样的?

    5G提供的是通信网络服务,数字化转型需要网络服务,但并不是必须使用5G网络,也就是说5G在数字化转型中并不是必虚的,但可以作为备选项,不过在某些行业比如农业.林业.牧业.港口.建筑等布设有线网络.无线 ...

  9. CentOS 7.9 安装 Containerd-1.6.5

    一.CentOS 7.9 安装 Containerd-1.6.5 地址 https://containerd.io/downloads 在安装containerd前,我们需要优先升级libseccom ...

  10. win10设置或更改硬盘图标

    1.首先要找到".ico"的图标素材,存放在要更改图标的硬盘根目录,可命名为a.ico.图片素材大家可以去一些素材网找找,一般可以找到很多. 2.在该硬盘分区空白处鼠标右键新建一个 ...