C Language Review: Memory Model 2

function call model

Fundamental

In fact, it is constantly jumping from one memory to another.

Function call variable passing analysis

  1. A main program consists of n functions, how many heap areas will the C++ compiler create? How many stack areas are there?

    Answer: A program has only one heap area and one stack area.

  2. When the function is nested and called, after the actual parameter address is passed to the formal parameter, how does the C++ compiler manage the life cycle of the variable?

    The variable of the upper level can be used in the next level call, and the upper level variable still exists after the parameter is passed. The lower-level variables cannot be called in the upper-level, except for the variables created in the heap area. The life cycle of the upper-level and lower-level variables is mainly determined by the characteristics of the stack: first-in, last-out, last-in, first-out

Analysis: function A, calling function B, variables passed through parameters (can the memory space be used?)

Tip: Establishing the correct program execution memory layout is the key to learning C.

Pay attention to wild pointers;

The growth direction of the stack area;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324660216&siteId=291194637