当前位置:网站首页>C Expert Programming Chapter 4 The Shocking Fact: Arrays and Pointers Are Not the Same 4.5 Other Differences Between Arrays and Pointers
C Expert Programming Chapter 4 The Shocking Fact: Arrays and Pointers Are Not the Same 4.5 Other Differences Between Arrays and Pointers
2022-08-04 04:46:00 【weixin_Guest time】
/*Another difference between arrays and pointers
*Poems array
*Save the address of the data to save data
*indirect access data, first get the content of the pointer, directly access the data, A [i] is just the only thingSimply take a+i as the address to get the data
as the address, and then extract the data from this address
If the pointer has a subscript [i], add i as the address to the content of the pointer
and extract from itdata
*usually used for dynamic data structures typically used to store a fixed number of elements of the same data type
*relevant functions are malloc(), free() implicit allocation and deletion
*usually refers to anonymousThe data itself is the variable name
*/
/* Both arrays and pointers can be initialized with string constants in their definitions.But the underlying mechanism is different
*When defining a pointer, the compiler does not allocate space for the object pointed to by the pointer, it just allocates space for the pointer itself, unless
* is defined while assigning a pointer to aString constants are initialized.
*/
/* Allocate memory space for both p and "breakfruit" */
char *p = "breadfruit";
/* In ANSI C, the character created by initializing pointersString constants are defined as read-only.If you try to modify the value of this
* character through the pointer, the program will exhibit undefined behavior.
*/
float *pip = 3.14; /* ERROR!Can't compile */
/* Note that this is only true for string constants, don't expect to allocate space for constants like floating point numbers */
/*Arrays can also be initialized with string constants*/
char a[] = "gooseberry";
/*In contrast to pointers, arrays initialized with string constants can be modified.
*Individual characters can be changed later.
*/
For example:
strncpy(a, "black", 5);
边栏推荐
- Turn: Management is the love of possibility, and managers must have the courage to break into the unknown
- 商城App开发都有哪些功能呢
- 大型连锁百货运维审计用什么软件好?有哪些功能?
- C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.5 数组和指针的其他区别
- 系统设计.如何设计一个秒杀系统(完整版 转)
- docker安装mysql与宿主机相差8小时的问题。
- 深度学习21天——卷积神经网络(CNN):实现mnist手写数字识别(第1天)
- JVM Notes
- Tensors - Application Cases
- 3000字,一文带你搞懂机器学习!
猜你喜欢

2003. 每棵子树内缺失的最小基因值 DFS

震惊,99.9% 的同学没有真正理解字符串的不可变性

How to simplify the automation of modern e-procurement?

将xml标签转换为txt(voc格式转换为yolo方便进行训练)

7-2 LVS+DR Overview and Deployment

How to systematically plan and learn software testing?

关于yolo7和gpu

【机器学习】21天挑战赛学习笔记(一)

Take care of JVM performance optimization (own note version)

软件测试如何系统规划学习呢?
随机推荐
How to simplify the automation of modern e-procurement?
DataTable使用Linq进行分组汇总,将Linq结果集转化为DataTable
【机器学习】21天挑战赛学习笔记(一)
How to systematically plan and learn software testing?
7. The principle description of LVS load balancing cluster
2022软件测试面试题 最新字节跳动50道真题面试题 刷完已拿下15k 附讲解+答疑
C专家编程 第5章 对链接的思考 5.1 函数库、链接和载入
某母婴小程序加密参数解密
[Ryerson emotional speaking/singing audiovisual dataset (RAVDESS)]
System design. Seckill system
系统设计.如何设计一个秒杀系统(完整版 转)
【21天学习挑战赛】直接插入排序
leetcode 12. 整数转罗马数字
八年软件测试工程师带你了解-测试岗进阶之路
mysql index notes
QT 如何识别文件的编码格式
【一步到位】Jenkins的安装、部署、启动(完整教程)
go module的介绍与应用
2022年PMP考试延迟了,该喜该忧?
What are the steps for how to develop a mall system APP?