int *p,cons int *p,int const *p,int * const p,const int * const p,int const * const p的差别
加有constkeyword的几种情况的辨析
|
const修饰的代码 |
含义(特点) |
等价性 |
|
int *p = # |
1. 2. 3. |
权限最大 |
|
cons int *p = # |
1、const放在左边意味着指向的是常量。这个常量不能够改动, 2、p = &data; (地址能够改动) 3、*p = 30;(这个时候是错误的) |
这两者等价(应用:查看别人的账户) |
|
int const *p = # |
(和上面的等价)限定仅仅能读不能够改动,地址能够移动 |
|
|
int * const p = # |
不能够改动自己的地址。可是能够通过*p来改动自己的值 |
|
|
const int * const p = # |
不能够改动地址来看其他的值,也不能够改动自己的,仅仅能看自己的 |
1、可看自己 2、不改自己 3、不能看别人 |
|
int const * const p = # |
限定仅仅能看自己的账户,仅仅能读不可写 |
仅仅能在初始化的时候才可以赋值(const限定了不能随便改动变量)
const总结
const在’*’左边意味着我指向的是常量。
const在’*’右边意味着我指针式一个常量。
当把上面的p=&data;改成了*p
= 3;这个时候就不能够了。截图例如以下:
int const *p
int * const p; 不能够改动自己的地址,可是能够通过*p来改动自己的值
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdG90b3R1enVvcXVhbg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
能够通过*p的方式进行改动
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdG90b3R1enVvcXVhbg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
6.const int * const p = &data;
这样的方式仅仅能看自己的,不能改动别人的,也不能改变自己。
仅仅能看自己:
int *p,cons int *p,int const *p,int * const p,const int * const p,int const * const p的差别的更多相关文章
- The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (new View.OnClickListener(){}, String, int)
package comxunfang.button; import android.support.v7.app.ActionBarActivity; import android.os.Bundle ...
- C# 求余 int a = 371 / 100 % 10,求a的结果为多少?//nt 和int类型计算得到的结果还是int类型
//int 和int类型计算得到的结果还是int类型 eg:int a = 371 / 100 % 10,求a的结果为多少? 首先371除以100,再让此结果除以10求余数. 一 371除以100得到 ...
- Scala 中的函数式编程基础(三)
主要来自 Scala 语言发明人 Martin Odersky 教授的 Coursera 课程 <Functional Programming Principles in Scala>. ...
- the difference between const int *, int * const, int const *
Some people may be confused about the sequence of const and * on declaration in C++/C, me too. Now I ...
- int *const && int const * && const int *的区别
ANSIC允许声明常量,常量和变量不同,常量就是不可以改变的量,用关键字const来修饰 比如:const int a int const a 以上两种声明方式是一样的,我们不需要考虑const和in ...
- const int *
5.Please choose the right statement about constusage: A.const int a;//const interger B.int const a;/ ...
- 【C++】int、const char*、char*、char、string之间的转换
#include "stdafx.h" #include<string> #include<vector> #include<iostream> ...
- 对于这个函数const int func(const int& a) const声明中,三个const分别是什么意思?
第一个const 函数的返回值类型是const. 这个const修饰没什么意义,你可以想象一下: 既然是函数的 返回值,而且是值传递的形式,是否const有什么意义.如果指针(引用)传递,怎表示返回值 ...
- caffe: compile error : undefined reference to `cv::imread(cv::String const&, int)' et al.
when I compile caffe file : .build_debug/lib/libcaffe.so: undefined reference to `cv::imread(cv::Str ...
- int * const 与 const int * 的区别
type * const 与 const type * 是在C/C++编程中特别容易混淆的两个知识点,现在就以 int * const 和 const int * 为例来简略介绍一下这两者之间的区别. ...
随机推荐
- 命令模式之2 Invoker Vs. Client
当程序中直接编写下达命令的语句如new Cmd1().execute()时.一般会将调用者与客户类合二为一. 在GUI程序中.下达命令的语句通常包括在底层框架中.或者说底层框架包括了调用者.这时程序猿 ...
- [Android中级]使用Commons-net-ftp来实现FTP上传、下载的功能
本文属于学习分享,如有雷同纯属巧合 利用业余时间.学习一些实用的东西,假设手又有点贱的话.最好还是自己也跟着敲起来. 在android上能够通过自带的ftp组件来完毕各种功能.这次是由于项目中看到用了 ...
- 为代码减负之<三>视图(SQL)
在设计数据库时为了降低数据冗余.一般都会依照三范式去设计,但有时我们在查询时须要通过一字段获取跟这 个字段相关联的好几个字段.可是他们又分布在不同的表中,这时候假设依照正常途径走的话须要同一时候查询好 ...
- Gretna2.0 使用过程中遇到的问题
在做Normalize的时候,报错"Cannot find T1 image (e.g. *.dcm in T1 Directory), Please Check again!", ...
- hdoj--1201--18岁生日(模拟)
18岁生日 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- maven的pom.xml配置标签
转自:https://blog.csdn.net/wf787283810/article/details/76188595 <project xmlns="http://maven.a ...
- [jzoj 6101] [GDOI2019模拟2019.4.2] Path 解题报告 (期望)
题目链接: https://jzoj.net/senior/#main/show/6101 题目: 题解: 设$f_i$表示从节点$i$到节点$n$的期望时间,$f_n=0$ 最优策略就是如果从$i, ...
- 修改mysql连接的密码
mysql8.0修改密码: ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的password'; msyql开启实现 ...
- c# post方式请求java form表单api
using System; using System.Collections.Generic; using System.Net.Http; namespace ConsoleApplication1 ...
- H5自带进度条&滑块
一.H5自带进度条 <div id="d1"> <p id="pgv">进度:0%</p> <progress id= ...