当前位置:网站首页>轻轻松松理解指针
轻轻松松理解指针
2022-06-26 00:13:00 【原来是这样^^】
在讲指针之前先要了解内存
内存就是电脑用来存储数据的地方,他有4G,8G,16G,32G等
像那么大的内存我们就需要管理,就像我们学校里的宿舍楼我们会把它分为各个不同的宿舍,并且每个宿舍会有唯一且不同的地址,比如0号宿舍,1号宿舍,2号宿舍等。
我们内存的一个最小单元就占用一个字节,相当于一个宿舍就占整栋宿舍楼的1个字节,并且我们会把每个内存单元编个唯一且不同号,如图下0,1,2......就像我们每个宿舍的门牌号如200,201,202,我们可以用这唯一的编号找到相应的内存单元

众所周知,整形int占4字节,所以它占4个蓝色框框,5就放在那块空间里(具体怎么放先不过多介绍,主要是我还没学到^^)
5这个数据存放好后我们需要知道它到底存放在内存的哪个角落我们就需要取地址符号&
取地址相当于现实生活中有人把我们宿舍的门牌号记录下来,&a就是把a的地址取出来

现实生活中我们知道了别人的地址是不是就可以对着地址找到对应的位置了,C语言也是如此

存放好地址后我们就可以解引用了 * , *是解引用操作符,*p的意思是通过p中的地址,找到p所指向的对象a,也就是说*p就是a
解引用后我们就可以选择修改或保持指向的值,相当于我们拿到宿舍的钥匙并通过门牌的地址找到对应的宿舍,进入宿舍后我们可以选择把宿舍整理一遍或原封不动

指针-指针=中间元素个数
注意:指针减指针要指向同一块空间
是地址-地址,不要解引用


边栏推荐
- 热血男孩滕文泽 受邀担任第六季完美童模全球总决赛形象大使
- Rollback Protection
- JSON instance (I)
- 丨EGFR FISH 探针解决方案
- Summary of knowledge points of catboost
- Maze walking
- CyCa children's physical etiquette Yueqing City training results assessment successfully concluded
- easyexcel读取文件
- Explication du script correspondant à l'assertion Postman
- GUN make (1) 简介
猜你喜欢

分布式系统(二)分布式事务的理解

Embedded c learning notes

论文阅读 Exploring Temporal Information for Dynamic Network Embedding

Viwi interface

readv & writev

甜酷少女金书伊 受邀担任第六季完美童模全球总决赛代言人

清甜女孩李斯霞 受邀担任第六季完美童模全球总决赛小主持人

What happens from entering a web address in the browser's input box to seeing the contents of the web page?

丨EGFR FISH 探针解决方案

biggan:large scale gan training for high fidelity natural image synthesis
随机推荐
热血男孩滕文泽 受邀担任第六季完美童模全球总决赛形象大使
28. contour discovery
ActivityManager kill reason
Installing MySQL databases in FreeBSD
Embedded c learning notes
Viwi interface
What happens from entering a web address in the browser's input box to seeing the contents of the web page?
Talking about interface test (I)
Redis的使用
Data analysis - similarities and differences between C-end and b-end data analysis
Pixel6 unlock bootloader
17.11 std:: atomic continuation, std:: async in-depth discussion
Common deep learning optimizers
biggan:large scale gan training for high fidelity natural image synthesis
弹性蛋白酶的用途和化学性质
2022 Anhui province safety officer C certificate examination practice questions simulated examination platform operation
Difference between app test and web test
26. histogram back projection
浅谈接口测试(二)
Distributed systems (II) understanding of distributed transactions