当前位置:网站首页>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);
边栏推荐
- For Qixi Festival, I made a confession envelope with code
- There is an 8 hour difference between the docker installation of mysql and the host.
- 21 days learning challenge 】 【 sequential search
- 解决错误:npm WARN config global `--global`, `--local` are deprecated
- 【云原生--Kubernetes】Pod资源管理与探针检测
- Take care of JVM performance optimization (own note version)
- PHP高级开发案例(1):使用MYSQL语句跨表查询无法导出全部记录的解决方案
- 深度学习环境配置
- 使用Patroni回调脚本绑定VIP的坑
- 系统设计.如何设计一个秒杀系统(完整版 转)
猜你喜欢

文件内容的操作

转:管理是对可能性的热爱,管理者要有闯进未知的勇气

企业直播风起:目睹聚焦产品,微赞拥抱生态

2022 Hangzhou Electric Power Multi-School League Game 5 Solution

SQL interview Questions

某母婴小程序加密参数解密

SQL query String field less than 10 how to check

ADC噪声全面分析 -03- 利用噪声分析进行实际设计

There is an 8 hour difference between the docker installation of mysql and the host.

系统设计.秒杀系统
随机推荐
Introduction to mq application scenarios
7-3 LVS+Keepalived集群叙述与部署
The Shell function
深度学习21天——卷积神经网络(CNN):实现mnist手写数字识别(第1天)
【21天学习挑战赛】顺序查找
劝退背后。
企业直播风起:目睹聚焦产品,微赞拥抱生态
7.LVS负载均衡群集之原理叙述
【id类型和NSObject指针 ObjectIve-C中】
Tensors - Application Cases
For Qixi Festival, I made a confession envelope with code
Cache pool of unity framework
【21天学习挑战赛】图像的旋转问题(二维数组)
Oracle与Postgresql在PLSQL内事务回滚的重大差异
结构体函数练习
Deep learning -- CNN clothing image classification, for example, discussed how to evaluate neural network model
中信证券网上开户怎么开的?安全吗?
2022 Hangzhou Electric Power Multi-School League Game 5 Solution
如何打造一篇优秀的简历
Take care of JVM performance optimization (own note version)