当前位置:网站首页>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);
边栏推荐
- day13--postman接口测试
- See how DevExpress enriches chart styles and how it empowers fund companies to innovate their business
- 8.Haproxy 搭建Web集群
- 商城系统APP如何开发 都有哪些步骤
- How to keep the source code confidential in the development under the burning scenario
- 【技巧】借助Sentinel实现请求的优先处理
- 【C语言进阶】程序环境和预处理
- A Preliminary Study of RSS Subscription to WeChat Official Account-feed43
- 7-2 LVS+DR Overview and Deployment
- JVM的内存模型简介
猜你喜欢

How to keep the source code confidential in the development under the burning scenario

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

八年软件测试工程师带你了解-测试岗进阶之路

烧录场景下开发如何进行源代码保密工作

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

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

文件系统的简单操作

PL/SQL Some Advanced Fundamental

How to simplify the automation of modern e-procurement?

7-1 LVS+NAT load balancing cluster, NAT mode deployment
随机推荐
2022软件测试面试题 最新字节跳动50道真题面试题 刷完已拿下15k 附讲解+答疑
How to keep the source code confidential in the development under the burning scenario
go module的介绍与应用
unity框架之缓存池
2022 software test interview questions The latest ByteDance 50 real interview questions, 15k have been won after brushing, with explanation + Q&A
Large chain best freight d audit with what software?What are the functions?
2022 Hangzhou Electric Power Multi-School League Game 5 Solution
结构体指针知识要点总结
A Preliminary Study of RSS Subscription to WeChat Official Account-feed43
Turn: Management is the love of possibility, and managers must have the courage to break into the unknown
How to dynamically add script dependent scripts
For Qixi Festival, I made a confession envelope with code
小程序 + 电商,玩转新零售
OpenGL绘制一个圆锥
Take care of JVM performance optimization (own note version)
[C language advanced] program environment and preprocessing
2.15 keil使用电脑端时间日期
7-1 LVS+NAT load balancing cluster, NAT mode deployment
2003. 每棵子树内缺失的最小基因值 DFS
技术解析|如何将 Pulsar 数据快速且无缝接入 Apache Doris