当前位置:网站首页>Spatial attribute overview C language
Spatial attribute overview C language
2022-07-18 21:27:00 【Kang Laicheng】
Preface
As a non subject student , Let me say before that I don't know the difference between different storage , Just vaguely understand what the stack is and what the heap is , But these foundations are also very important , A general understanding allows us to have new ideas when solving some problems .
One 、 Several segments stored
Different variables and different operations apply for different spatial positions , Here is a brief introduction to the general storage content of each space .
The stack area : Generally, it is used as the location where some temporary variables are stored during program compilation , The size is generally 2m or 1M.
Heap area : Completely controlled by the programmer malloc The opened memory is concentrated in the heap , It's usually 2G about .
code paragraph : The code we write is stored in this place .
rodata paragraph : Where some constants are stored .
data paragraph : Where class variables are stored , For the time being, it can be understood as except rodata Everything in it is here , Here's about static I'll talk more about it in other articles later .
Two 、rodata Segment and data The difference caused by paragraph
Through the introduction above , We know rodata Is where constants are stored , This area is only allowed to read but not write , Therefore, the defined constants cannot be modified , Here is a code to explain .
#include <stdio.h>
int main()
{
char *s = "hiHiHi";
s[0] = 'H';
printf("%s",s);
}This sentence is actually wrong , Before you understand that different variables will be stored in different locations , I certainly don't understand why this went wrong , Let's look at the correct code first .
#include <stdio.h>
int main()
{
char s[] = "hiHiHi";
s[0] = 'H';
printf("%s",s);
}Pointers and arrays are replaced here , Why did you let this program pass ? When it was originally a pointer, this string of data was stored according to a constant , Nature will exist rodata paragraph , And that position is read-only and not written , So you can't change , And the array is in data Segment stored data , It will change naturally .
summary
The understanding of spatial attributes can give us more ideas when solving problems , As the basic skill of writing programs, it is very important , It's not about static Etc , This part will appear in later articles .
边栏推荐
- Ten million level data MySQL distinct group by
- Netstat common scene record
- [C language brush leetcode] 134 Gas station (m)
- On array method reconstruction and re encapsulation -foreach map -- push (), unshift (), shift (), map (), filter (), every (), some (), reduce ()
- C language as a push box
- 为什么网络安全在工厂中很重要?
- R language ggplot2 visualization: use the ggballoonplot function of ggpubr package to visualize faceted balloon graph (visualization of contingency table composed of two classification variables), fac
- 不同的图像patch由不同的专家模型来处理!南洋理工&Mila稀疏融合混合专家模型SF-MoE,具有超强泛化能力!代码已开源!...
- True question of CCF (anger takes 100 faints)
- 剑指 Offer 57. 和为s的两个数字
猜你喜欢

Based on servlet project -- blog system

Use of prettier code formatting tool

(手工)【sqli-labs54-57】限制注入次数:联合注入、报错回显、GET注入
![(manual) [sqli-labs54-57] limit the number of injections: joint injection, error echo, get injection](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
(manual) [sqli-labs54-57] limit the number of injections: joint injection, error echo, get injection

劍指 Offer 57. 和為s的兩個數字

Daily question brushing record (XXV)

裁员之水天上来

Sql笔记

VMware recovery snapshot failed to create an anonymous paging file of 5040 MB: insufficient system resources to complete the requested service

Classic application method of installing HAP on Hongmeng development board
随机推荐
Topic 2-iis write permission vulnerability analysis and traceability
Win10 如何将FAT32格式磁盘不用格式化无损转化为NFTS格式
The thermal characteristics of this heater
I2C通信协议实现在OLED显示屏数据显示
On array method reconstruction and re encapsulation -foreach map -- push (), unshift (), shift (), map (), filter (), every (), some (), reduce ()
Introduction to sap appgyver
OSPF special area
R语言ggplot2可视化:使用ggpubr包的gghistogram函数可视化直方图、使用add参数在直方图中添加均值虚线竖线、横轴添加轴须图(rug plot)
Flutter draws very interesting Bezier curve animation
Leetcode+ 86 - 90 double pointer, backtracking, interval DP topics
New construction process of Hongmeng application development project and generation method of HAP package
[cloud native] Devops (IV): integrated sonar Qube
Jenkins installation
R语言使用dplyr包的arrange函数进行dataframe排序、arrange函数基于一个字段(变量)进行降序排序实战
Redis - detailed explanation of slot management commands
About SQL: orcale SQL, why is the foreign key inventory ID statement of the merchant table invalid
鲁汶大学招募博士后研究员,利用AI/ML对太阳活动区图像进行分析和耀斑预测...
[C language brush leetcode] 2155 All subscripts with the highest score in the group (m)
Part 13: implementation of STM32 I2C serial bus communication
Mathematical method - random integer in the packaging range - six digit random verification code - random color string - decimal conversion and decimal places retention