当前位置:网站首页>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;
}
边栏推荐
- C杂讲 浅拷贝 与 深拷贝
- 听哥一句劝,按这套嵌入式的课程内容和课程体系去学习
- [NLP] bert4vec: a sentence vector generation tool based on pre training
- 018.有效的回文
- Popularization of security knowledge - twelve moves to protect mobile phones from network attacks
- 美新泽西州州长签署七项提高枪支安全的法案
- Why data Tiering
- Mapreduce实例(九):Reduce端join
- 五月集训总结——来自阿光
- Safety notes
猜你喜欢
Can I learn PLC at the age of 33
CAPL 脚本打印函数 write ,writeEx ,writeLineEx ,writeToLog ,writeToLogEx ,writeDbgLevel 你真的分的清楚什么情况下用哪个吗?
Mapreduce实例(四):自然排序
C#/. Net phase VI 01C Foundation_ 01: running environment, process of creating new C program, strict case sensitivity, meaning of class library
Redis distributed lock implementation redison 15 questions
Defensive C language programming in embedded development
Segmentation sémantique de l'apprentissage profond - résumé du code source
Elk project monitoring platform deployment + deployment of detailed use (II)
听哥一句劝,按这套嵌入式的课程内容和课程体系去学习
I2C summary (single host and multi host)
随机推荐
Single chip microcomputer realizes modular programming: Thinking + example + system tutorial (the degree of practicality is appalling)
Cap theory
【深度学习】语义分割:论文阅读(NeurIPS 2021)MaskFormer: per-pixel classification is not all you need
MapReduce instance (VIII): Map end join
33岁可以学PLC吗
[CV] target detection: derivation of common terms and map evaluation indicators
There are software load balancing and hardware load balancing. Which one to choose?
Canoe cannot automatically identify serial port number? Then encapsulate a DLL so that it must work
May brush question 03 - sorting
Safety notes
Yarn organizational structure
【深度學習】語義分割-源代碼匯總
硬件工程师的真实前途我说出来可能你们不信
51单片机进修的一些感悟
[deep learning] semantic segmentation: paper reading: (2021-12) mask2former
一大波开源小抄来袭
单片机如何从上电复位执行到main函数?
Competition vscode Configuration Guide
Canoe CAPL file operation directory collection
Mapreduce实例(五):二次排序