Code Segment and Data Segment: Memory Layout of a Program


  1. #include <stdio.h>
  2.  
  3. int g_i  =  100/* A global variable */
  4. int g_j;  /* An uninitialized global variable */
  5.  
  6. int main ( void )  /* A function */
  7. {
  8.      int l_i  =  1/* A local variable */
  9.      static  int s_i  =  2/* A static local variable */
  10.      int c;
  11.      for  (=  0; c <  1000; c ++ )
  12.      {
  13.         l_i  += c;
  14.      }
  15.  
  16.      return  0;
  17. }

===High address ======================================================================

stack(used to store automatic variables (non-static local variables) and the calling environment each time a function is called)

int c;   函数的形参

-------------------------


--------------------------

HEAP (managed by mallocrealloc and free))

---------------------------------------------------

.bss(global variables and static variables that are not initialized)

  1. int g_j;  /* An uninitialized global variable */

----------------------------------------------------------------------------------------------------------------

.data (global variables and static variables that are initialized )           

  1. int g_i  =  100/* A global variable  */                              
  static   int  s_i  =   2 /* A static local variable */ 

-----------------------------------------------------                                  .data .text  组成可执行文件

 Code segment = Text Segment

 int l_i = 1/* A local variable */

  main();                                                

===LOW address ======================================================================================================


猜你喜欢

转载自blog.csdn.net/yangchaofeng001/article/details/41833537