当前位置:网站首页>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);
边栏推荐
- 8.Haproxy 搭建Web集群
- 2003. 每棵子树内缺失的最小基因值 DFS
- This Thursday evening at 19:00, the fourth live broadcast of knowledge empowerment丨The realization of equipment control of OpenHarmony smart home project
- 基于 SSE 实现服务端消息主动推送解决方案
- 杭电多校-Slipper-(树图转化+虚点建图)
- 转:管理是对可能性的热爱,管理者要有闯进未知的勇气
- 深度学习21天——准备(环境配置)
- if,case,for,while
- C专家编程 第5章 对链接的思考 5.3 函数库链接的5个特殊秘密
- Introduction to mq application scenarios
猜你喜欢
随机推荐
烧录场景下开发如何进行源代码保密工作
Converts XML tags to TXT format (voc conversion for yolo convenient training)
信息学奥赛一本通 1312:【例3.4】昆虫繁殖
10 Convolutional Neural Networks for Deep Learning 3
el-Select 选择器 底部固定
[C language advanced] program environment and preprocessing
如何简化现代电子采购的自动化?
JVM的内存模型简介
Stop behind.
C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.2 我的代码为什么无法运行
附加:对于“与数据表对应的实体类“,【面对MongoDB时,使用的@Id等注解】和【以前面对MySQL时,使用的@Id等注解】,是不同的;
mysql index notes
企业直播风起:目睹聚焦产品,微赞拥抱生态
7-3 LVS+Keepalived集群叙述与部署
docker安装mysql与宿主机相差8小时的问题。
【id类型和NSObject指针 ObjectIve-C中】
System design. Seckill system
C专家编程 第5章 对链接的思考 5.1 函数库、链接和载入
看DevExpress丰富图表样式,如何为基金公司业务创新赋能
unity框架之缓存池









