当前位置:网站首页>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);
边栏推荐
- Mini program + e-commerce, fun new retail
- C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.2 我的代码为什么无法运行
- Uni-app 小程序 App 的广告变现之路:全屏视频广告
- Structure function exercise
- 【评价类模型】Topsis法(优劣解距离法)
- 杭电多校-Slipper-(树图转化+虚点建图)
- C专家编程 第5章 对链接的思考 5.1 函数库、链接和载入
- Postgresql源码(66)insert on conflict语法介绍与内核执行流程解析
- 大型连锁百货运维审计用什么软件好?有哪些功能?
- For Qixi Festival, I made a confession envelope with code
猜你喜欢
随机推荐
【技巧】借助Sentinel实现请求的优先处理
SQL interview Questions
42. 接雨水
【21 Days Learning Challenge】Direct Insertion Sort
Introduction and application of go module
大型连锁百货运维审计用什么软件好?有哪些功能?
某母婴小程序加密参数解密
如何动态添加script依赖的脚本
如何打造一篇优秀的简历
How to dynamically add script dependent scripts
PL/SQL Some Advanced Fundamental
7-2 LVS+DR Overview and Deployment
Jenkins 导出、导入 Job Pipeline
Uni-app 小程序 App 的广告变现之路:全屏视频广告
深度学习21天——准备(环境配置)
关于yolo7和gpu
OpenGL绘制圆
使用Loadrunner进行性能测试
杭电多校-Slipper-(树图转化+虚点建图)
2022软件测试面试题 最新字节跳动50道真题面试题 刷完已拿下15k 附讲解+答疑

![The video of machine learning to learn [update]](/img/e7/c9a17b4816ce8d4b0787c451520ac3.png)







