当前位置:网站首页>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);
边栏推荐
- [Skill] Using Sentinel to achieve priority processing of requests
- [Ryerson emotional speaking/singing audiovisual dataset (RAVDESS)]
- drools from download to postman request success
- PHP高级开发案例(1):使用MYSQL语句跨表查询无法导出全部记录的解决方案
- 【21天学习挑战赛】顺序查找
- 3000字,一文带你搞懂机器学习!
- redis中常见的面试题
- 商城系统APP如何开发 都有哪些步骤
- 2022年PMP考试延迟了,该喜该忧?
- System design. Seckill system
猜你喜欢

This Thursday evening at 19:00, the fourth live broadcast of knowledge empowerment丨The realization of equipment control of OpenHarmony smart home project

How to simplify the automation of modern e-procurement?

Postgresql源码(66)insert on conflict语法介绍与内核执行流程解析

Towards Real-Time Multi-Object Tracking(JDE)

RSS订阅微信公众号初探-feed43

【C语言进阶】程序环境和预处理

Turn: Management is the love of possibility, and managers must have the courage to break into the unknown

SQL query String field less than 10 how to check

Oracle与Postgresql在PLSQL内事务回滚的重大差异

【21天学习挑战赛】图像的旋转问题(二维数组)
随机推荐
C专家编程 第5章 对链接的思考 5.6 轻松一下---看看谁在说话:挑战Turning测验
【机器学习】21天挑战赛学习笔记(一)
Metaverse "Drummer" Unity: Crazy expansion, suspense still exists
Mobile payment online and offline payment scenarios
SVM介绍以及实战
redis中常见的面试题
There is an 8 hour difference between the docker installation of mysql and the host.
2022年PMP考试延迟了,该喜该忧?
【技巧】借助Sentinel实现请求的优先处理
Simple operation of the file system
21 days learning challenge 】 【 sequential search
2022软件测试面试题 最新字节跳动50道真题面试题 刷完已拿下15k 附讲解+答疑
八年软件测试工程师带你了解-测试岗进阶之路
结构体函数练习
3000 words, is take you understand machine learning!
7.LVS负载均衡群集之原理叙述
leetcode 12. 整数转罗马数字
7. The principle description of LVS load balancing cluster
如何动态添加script依赖的脚本
7-1 LVS+NAT load balancing cluster, NAT mode deployment