Pointers and Constants
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的更多相关文章
- function 的声明
<?php function test() { echo "abc"; } test(); ?> 结论: 一 编译 a.对 函数声明进行词法分析和语法分析:在语法分析中 ...
- 【转】const int *p和int * const p的区别(常量指针与指向常量的指针)
[转]作者:xwdreamer 出处:http://www.cnblogs.com/xwdreamer 对于指针和常量,有以下三种形式都是正确的: const char * myPtr = &am ...
- C++_class_powerpoint_1.1
Types and Declarations Boolean Type bool type – boolean , logic type bool literal – true, falseint a ...
- Constants in C++
The first motivation for const seems to have been to eliminate the use of preprocessor #define for v ...
- 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 ...
- Leetcode 笔记 116 - Populating Next Right Pointers in Each Node
题目链接:Populating Next Right Pointers in Each Node | LeetCode OJ Given a binary tree struct TreeLinkNo ...
- some OpenGL constants
some OpenGL constants This is from (https://github.com/peterderivaz/pyopengles/blob/master/gl2.py) G ...
- [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 ...
- [LeetCode] Populating Next Right Pointers in Each Node 每个节点的右向指针
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...
随机推荐
- ELK基于ElastAlert实现日志的微信报警 ---docker环境
参考网址:https://github.com/anjia0532/elastalert-docker 1.拉取镜像: docker pull anjia0532/elastalert-docker: ...
- Elasticsearch:使用 GeoIP 丰富来自内部专用 IP 地址
转载自:https://blog.csdn.net/UbuntuTouch/article/details/108614271 对于公共 IP,可以创建表来指定 IP 属于哪个城市的特定范围.但是,互 ...
- 20220929-ArrayList扩容机制源码分析
示例代码 public class ArrayListSource { public static void main(String[] args) { ArrayList arrayList = n ...
- 第一个java程序进行总结
1.java程序编写-编译-运行的过程 编写:我们将编写的java代码保存在以".java"结尾的源文件中 编译:使用javac.exe命令编译我们的java源文件.格式:java ...
- 浅谈--ETCD的基本概念及用法
1. 简介 ETCD 是一个高可用的分布式键值数据库,可用于服务发现.ETCD 采用 raft 一致性算法,基于 Go 语言实现. raft是一个强一致的集群日志同步算法. ETCD使用gRPC,网络 ...
- DQL-聚合函数
DQL-聚合函数 SQL基本函数,聚合函数对一组值执行计算,并返回单个值,也被称为组函数. 聚合函数对一组值执行计算并返回单一的值.除 COUNT 以外,聚合函数忽略空值,如果COUNT函数的应用对象 ...
- Spring Boot:自定义 Whitelabel 错误页面
一.概述在本文中,我们将研究如何禁用和自定义 Spring Boot 应用程序的默认错误页面,因为正确的错误处理描述了专业性和质量工作. 2.禁用白标错误页面 首先,让我们看看如何通过将server. ...
- redis的几个优化点
1. redis读写速度慢 可以将redis单实例改为redis集群 2. redis报OOM redis内存溢出,调大redis内存:增加redis.conf中的maxmemory 的值.如果red ...
- Java中String被称为不可变字符串的原因
很多东西,看似可变,实际上不过是是新桃换旧符罢了. 代码: /** * String之所以被称为不可变字符串 */ static void testString(){ String str = &qu ...
- java学习之spirng的aop
AOP技术 0x00前言 什么是AOP技术:在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期间动态代理实现程序功能的统一维护的 ...