当前位置:网站首页>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);
边栏推荐
猜你喜欢
mq应用场景介绍
The Shell function
七夕节,我用代码制作了表白信封
某母婴小程序加密参数解密
el-Select 选择器 底部固定
软件测试如何系统规划学习呢?
drools from download to postman request success
Structure function exercise
附加:对于“与数据表对应的实体类“,【面对MongoDB时,使用的@Id等注解】和【以前面对MySQL时,使用的@Id等注解】,是不同的;
Eight guiding principles to help businesses achieve digital transformation success
随机推荐
manipulation of file contents
Senior PHP development case (1) : use MYSQL statement across the table query cannot export all records of the solution
嵌入式数据库开发编程MySQL(全)
2022年软件测试——精选金融银行面试真题
42. 接雨水
mysql index notes
21 days learning challenge 】 【 sequential search
go module的介绍与应用
2.15 keil使用电脑端时间日期
杭电多校-Slipper-(树图转化+虚点建图)
7.LVS负载均衡群集之原理叙述
Introduction to the memory model of the JVM
Converts XML tags to TXT format (voc conversion for yolo convenient training)
The Shell function
劝退背后。
关于yolo7和gpu
某母婴小程序加密参数解密
C Expert Programming Chapter 4 The Shocking Fact: Arrays and pointers are not the same 4.4 Matching declarations to definitions
[21 Days Learning Challenge] Image rotation problem (two-dimensional array)
八年软件测试工程师带你了解-测试岗进阶之路