Running space

A program to the operating system for its operation of the memory block is divided into four regions

(1) the stack area (stack): allocating local variables is released automatically by the compiler, storage allocated to run a function, the function parameters, return data, and return address. Operate similarly to a stack data structure

(2) heap (heap): general distribution and released by the programmer, if the programmer does not release at the end of the program may be recovered by the operating system. Management style is similar to the list

(3) global area (static area) (static): store global variables. Static data, constants. After the end of the program released by the system.

(4) the constant region: storing all kinds of variables. After the end of the program released by the system.

(5) the program code area: storing binary code function body

#include<stdio.h>
#include<malloc.h>

typedef struct Node
{
    int data;
    struct Node *next;
} LinkListNode;

LinkListNode *CreateNode(void)
{
    LinkListNode * P, * heap, Stack;
 // heap by the malloc function pointed to the space application, allocated on the heap 
    heap = (LinkListNode *) malloc ( the sizeof (LinkListNode));
    heap->data = 6;
    heap -> Next = NULL;
     // stack variables allocated on the stack space 
    stack * = heap; // copy the content to the node heap stack node
 //     P = & stack; 
    P = heap;
     return P;
}

int main ()
{
    LinkListNode *head,*x;
    int y;
    head = CreateNode();
    x = head;
    printf("%x:%d %d\n",x,x->data,x->next);
    y = x->data;
    printf("%x:%d %d\n",x,y,x->next);
    return 0;
}
/*
Run Results: 1.p = & stack; effective
                19fec0:6 0
                19fec0:1703728 4198625
        2.p = heap; effective
                673aa0: 6 0
                673aa0: 6 0
Summary: After partitioning the amount of local stack address is passed to the main function, the amount of space is due to the local release system can be deactivated therebetween content
        Space is allocated on the heap, although the amount of the local sub-function, but is passed to the main function, since this space is controlled by the currently running program, has not been released, and therefore the content is still retained                
*/

 

Guess you like

Origin www.cnblogs.com/Safe-Man/p/11959061.html