1.c ++ memory partition model
c ++ program running in the process, the memory is divided into the following four partitions
Code area: Programs binary code of the program, including comments will be placed in this area
Global Area: storing static variables, global variables, constants (string constants and const modified constant), the data in this area will be freed by the operating system at the end of the program
Stack Area: used to store local variables, function parameters, etc., are automatically released and allocated by the compiler, so it is not a return address stack area,
Heap: storage objects (using the new operator, will be introduced later) released by the programmer assigned, if we do not release the program ends by the operating system release
c ++ by the new keyword will open up data to the stack area
If you are a new array
note
Code area and the global area are compiled into exe executable file when it is already there, but the stack area and heap area after the implementation of the program exe file generated
2. Why divide memory (memory division sense)
The different data in different areas, giving different life cycles, improve flexibility of programming
3. references
Use a reference to a variable surnamed
Previous article modifies the transfer address argument, argument passed by value does not modify, as a function of a reference parameter modifies the argument, the process of simplifying complex argument a pointer to modify
Local variables can not be returned as the return value of the function
If local static variables, you can return
Reference is essentially a pointer constant
Const reference
4. Functions Related
The basis of the previous series c ++ knowledge about the functions described here to add some functions advanced knowledge
1.c ++ functions can have default values in
2.c ++ function parameters can be used placeholder placeholder, the calling function is necessary to fill this position
3. function overloading
Definition: under the same scope, two different functions in different type or parameters or a different number of parameters sequentially. At this time, these two functions can be the same name. Improve reusability
Note: The function returns the value of the condition is not overloaded as a function
4. Reference may also function as a heavy load condition
5. Function overloading encountered default parameters Note