C程序存储空间分布

来源:互联网 发布:2017年网络语 编辑:程序博客网 时间:2024/05/16 06:46

      某实习笔试曾考程序的存储空间分布:

                    high addess

command argument

&environment variable 

stack (grows down)




heap (grows up)

uninitail data

initial data

program (程序正文段)

       low address


1.Program can be shared by multiple process.(多个进程共享,打开几个notepad,它们是共享同一份二进制代码的)

2.Initial data is the varible which  must be initial explicitly.Such as   int  cnt = 100 ; which is declared out of any function.(必须显式初始化的数据)

3.Unitial data is the varible which will be initialed to 0 or null pointer by the core,such as int cnt; which is declared out of any function.

(系统默认在程序开始执行前进行初始化的数据,函数体内的变量是不会自动初始化的,函数体外会自动初始化为0或空指针,且做正确类型的赋值,则整数就赋值0,指针就赋值null,题外话:calloc()函数则不会做正确的赋值)

4.Heap grows up,used to allocate the space when the program running.(动态分配)

5. Stack grows down,auto variable and some temp variable are her.

(自动变量和函数调用的一些信息:返回地址、调用者环境信息等,需要说明的是,递归调用在每次对应自身是,会使用一个新的帧,各自不影响)

6.Command line argument just like : int main(int argc ,char * argv[] )  {return 0;}

   And every program has a environment variables table.

(命令行参数和环境变量放在高地址,环境表是每个程序都用的,之前写CGI程序,就是通过环境变量来处理请求响应的)


原创粉丝点击