当前位置:网站首页>Constants and pointers
Constants and pointers
2022-07-06 09:54:00 【@sen】
One 、 Constant pointer
#include<stdio.h>
int main()
{
int num = 520;
const int cnum = 880;
const int* pc = &cnum; //pc Deposited cnum The address of
//*pc Deposited cnum Value
printf("cnum:%d,&cnum:%p\n", cnum, &cnum);
printf("*pc:%d,pc:%p\n", *pc, pc);
pc = # // change pc The storage address is num;*pc Deposited num Value
printf("num:%d,&num:%p\n", num, &num);
printf("*pc:%d,pc:%p\n", *pc, pc);
}
Two 、 pointer to const :(const keyword )
1、 Pointers can be modified to point to different constants
2、 Pointers can be modified to point to different variables
3、 You can use dereference to read the data pointed to by the pointer
4、 You cannot modify the data pointed to by dereference
#include <stdio.h>
int main()
{
int num = 520;
const int cnum = 880;
int* const p = #
*p = 1024; // The value pointed to by the pointer can be changed
printf("*p:%d\n", *p);
//p = &cnum;
//printf("*p:%d\n", *p); // Will report a mistake , The pointer itself cannot be modified
return 0;
} 3、 ... and 、 Constant pointer :(const keyword )
A constant pointer to a non constant quantity
---- The pointer itself cannot be modified
---- The value pointed to by the pointer can be modified
Constant pointer to constant
---- The pointer itself cannot be modified
---- The value pointed to by the pointer cannot be modified
Four 、 Point to “ Constant pointer to constant ” The pointer to
#include<stdio.h>
int main()
{
int num = 520;
const int cnum = 880;
const int* const p = #
const int* const* pp = &p;
printf("pp:%p, &p:%p\n", pp, &p); //pp Deposited p The address of
printf("*pp:%p, p:%p, &num:%p\n", *pp, p, &num);// Yes pp Make a layer of dereference , That is to say num The address of
printf("**pp:%d, *p:%d, num:%d\n", **pp, *p, num);// Yes pp Two levels of dereference , Deposit is num Value
return 0;
}
边栏推荐
- 一大波開源小抄來襲
- Mapreduce实例(七):单表join
- Mapreduce实例(八):Map端join
- 大学C语言入门到底怎么学才可以走捷径
- CANoe下载地址以及CAN Demo 16的下载与激活,并附录所有CANoe软件版本
- Counter attack of noodles: redis asked 52 questions in a series, with detailed pictures and pictures. Now the interview is stable
- Function description of shell command parser
- O & M, let go of monitoring - let go of yourself
- [flask] crud addition and query operation of data
- PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
猜你喜欢

Mapreduce实例(八):Map端join

C#/. Net phase VI 01C Foundation_ 01: running environment, process of creating new C program, strict case sensitivity, meaning of class library

I2C summary (single host and multi host)

Keep these four requirements in mind when learning single chip microcomputer with zero foundation and avoid detours

Mapreduce实例(六):倒排索引

Why can't TN-C use 2p circuit breaker?

Nc17 longest palindrome substring

CAPL 脚本对.ini 配置文件的高阶操作

What are the models of data modeling

MapReduce instance (VII): single table join
随机推荐
听哥一句劝,按这套嵌入式的课程内容和课程体系去学习
【深度学习】语义分割:论文阅读(NeurIPS 2021)MaskFormer: per-pixel classification is not all you need
嵌入式开发比单片机要难很多?谈谈单片机和嵌入式开发设计经历
Defensive C language programming in embedded development
硬件工程师的真实前途我说出来可能你们不信
What are the models of data modeling
max-flow min-cut
《ASP.NET Core 6框架揭秘》样章发布[200页/5章]
018. Valid palindromes
Competition vscode Configuration Guide
MapReduce instance (x): chainmapreduce
通过bat脚本配置系统环境变量
Libuv thread
小白带你重游Spark生态圈!
Hugo blog graphical writing tool -- QT practice
May brush question 03 - sorting
五月刷题02——字符串
Hard core! One configuration center for 8 classes!
The real future of hardware engineers may not be believed by you if I say so
Some thoughts on the study of 51 single chip microcomputer