您的位置:首页 > 其它

Text段、Data段和BSS段

2016-10-29 10:19 211 查看
不同的compiler在编译的过程中对于存储的分配可能略有不同,但基本结构大致相同。

大体上可分为三段:Text段、Data段和BSS段。

1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<iostream>
4 #include<string.h>
5 using namespace std;
6
7 static int a=1;//全局初始化区
8 int b=2;//全局初始化区
9 char *p;//全局未初始化区
10 char *p2;//全局未初始化区,BSS段
11 int *p3;//全局未初始化区 ,BSS段
12 int *p4;//全局未初始化区 ,BSS段
13 char *p5={"555555555"};//全局初始化区
14
15 int main(){
16     static int c=3;
17     int d=4;//内存栈
18     int e=7;//内存栈
19
20     char *p6={"555555555"};
21     p=(char*)malloc(sizeof(char)*10);//内存堆
22     p2=(char*)malloc(sizeof(char)*10);//内存堆
23     p3=(int*)malloc(sizeof(int));//内存堆
24     p4=(int*)malloc(sizeof(int)*10);//内存堆
25     for(int i=0;i<=9;i++)p4[i]=0x1;
26
27
28     *p3=0x123;
29     strcpy(p,"123456789");//文字常量区
30     strcpy(p2,"987654321");
31     strcpy(p2,"123456789");
32 }


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: