当前位置:网站首页>Pointer storage array C
Pointer storage array C
2022-07-16 04:58:00 【Kang Laicheng】
Preface
C The pointer of language is very easy and convenient after understanding , But before, I always left after compiling without paying attention warning, Study c++ Later, because of the stricter requirements for the use of pointers , The previous non-standard Pointer use slowly exposed .
One 、 How to store arrays with pointers
Arrays and functions represent the first address of a string of data or an operation , Then it can be represented by a pointer . But the specific type , Before I use several levels of pointer, I just swallow it and run it . Because with *a Can be used to represent an array , Let me always think that two-dimensional arrays are completely usable **a To represent the , On the force button platform, this can often complete the problem , But when you run on the compiler, you can quickly find **a It cannot complete the function of two-dimensional array . This is because he missed a very important feature : The pointer +1 Then pointing to the new location is different . Here we use a[3][4] give an example , The correct way of writing should be *a[][4], For the former +1 Span only sizeof(int) Distance of , While the latter is 4*sizeof(int), He can complete the function of two-dimensional array . But if you just store a two-dimensional array , Do you use int * Even char* It's all right , Because the type in front of them only represents them +1 Skip the distance , It doesn't affect them to store a first address .
Two 、 When the pointer is used C And C++ The difference between
Since any pointer can represent my array function, etc , Isn't my top talking nonsense ? Note that the above usage, except for the formal writing, will warning Of , however C Language for the convenience of programmers want to easily find the address at any time , The type of address allowed by the program only determines the address every time +1 Distance crossed , There is no limit to what he saves .c++ Be more strict in this respect , You will find that your type does not match or the level of the pointer is wrong, and you can't run the code , It is very important to know the format of writing pointer correctly !
summary
We should learn later c++ Novices must pay attention to the norms of writing pointers at ordinary times , Writing well about the application of a pointer can get twice the result with half the effort , The type of pointer should also be flexibly adjusted , Make the whole program very flexible .
边栏推荐
- [underlying principle] what is a socket? Why is the network inseparable from socket?
- PyTorch - 存储和加载模型
- Applet container technology greatly improves the development efficiency of hybrid apps
- SQL 2008 database migration
- [底层原理]Socket 究竟是什么? 为啥网络离不开 Socket?
- ObjectARX select entities to create block references
- 现有两个kafka的topic要通过Flink将数据原封不动的写入MYSQL 王方案一: 写两个F
- 水墨云怎么样?
- How to realize digital transformation? McKinsey: four steps of digital transformation
- build_opencv.sh
猜你喜欢

普通浏览器会泄露信息吗?使用安全浏览器如何做到隐私保护?

开鸿智谷 Niobe 407 正式并入OpenHarmony代码主干

螺旋矩阵

微信小程序测试点汇总

Still alive, LETV has 400 employees: Immortals' means of making money have been exposed

【路由优化】基于生物地理学优化的 HWSN 节能聚类协议附matlab代码

ABAP BAPI 复制标准项目模板实现项目立项
![[number recognition] handwritten number recognition based on knowledge base with matlab code](/img/06/6adab955a339f453249543baab1dc6.png)
[number recognition] handwritten number recognition based on knowledge base with matlab code

c语言基础篇:N子棋

plantUML使用总结
随机推荐
C语言自定义类型详解 —— 结构体、枚举、联合体
上课笔记(3)例题(2)——#567. 庆功会(beanfeast)
Some interview questions encountered recently -- WPF, C #, database
美团二面:为什么 Redis 会有哨兵?
深度学习神经网络的正向传播(一)
ES6中箭头函数 (=>)、三点运算符(...)的基本用法和注意事项(this指向)
信息系统项目管理师必背核心考点(四十一)风险管理计划
Knowledge points of driving license subject
测试如何发挥更大价值?聊聊测试左移和测试右移
A systematic framework for describing the impact of machine learning on greenhouse gas emissions
接口测试常用工具及测试方法
Expert, Alibaba Daniel quit and brought out the internal "high concurrency system design" learning manual
Introduction to C language compiler
SQL Server 中的异常处理
从矩阵中查找数字是否存在
一群南大学子靠科技出海,年入10亿
Tensor是如何让你的内存/显存泄漏的
Explain the exercises in Chapter 3 of C language
自定义类型详解(结构体、枚举,联合)
明解C语言第三章习题