当前位置:网站首页>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);
边栏推荐
猜你喜欢

7-3 LVS+Keepalived Cluster Description and Deployment

mq应用场景介绍

关于yolo7和gpu

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

Explain详解与实践

Significant differences between Oracle and Postgresql in PLSQL transaction rollback

A Preliminary Study of RSS Subscription to WeChat Official Account-feed43
![[21 Days Learning Challenge] Image rotation problem (two-dimensional array)](/img/51/fb78f36c71e1eaac665ce9f1ce04ea.png)
[21 Days Learning Challenge] Image rotation problem (two-dimensional array)

深度学习环境配置

2003. 每棵子树内缺失的最小基因值 DFS
随机推荐
go module的介绍与应用
Hangdian Multi-School-Slipper- (tree map conversion + virtual point mapping)
JVM的内存模型简介
Stop behind.
Learn iframes and use them to solve cross-domain problems
[Ryerson emotional speaking/singing audiovisual dataset (RAVDESS)]
SQL query String field less than 10 how to check
mysql索引笔记
文件内容的操作
OpenGL绘制一个圆锥
获取单选框选中内容
7-2 LVS+DR Overview and Deployment
图像处理之Bolb分析(一)
Eight guiding principles to help businesses achieve digital transformation success
将xml标签转换为txt(voc格式转换为yolo方便进行训练)
使用Loadrunner进行性能测试
How to open a CITIC Securities online account?is it safe?
C专家编程 第5章 对链接的思考 5.4 警惕Interpositioning
SVM介绍以及实战
【21天学习挑战赛】图像的旋转问题(二维数组)