|
new is a method of applying memory beyond the scope of general nature.
That is, after new, the language does not manage your memory space, but you manage it yourself.
In addition, the language features will automatically reclaim some memory space for you.
Such as
void fun()
{
int i; // The memory space of i here is applied
}
// was released outside.
//This is the so-called life cycle of the scope, that is, the memory space that will be released if the scope is exceeded.
The scope is divided into (non-standard naming):
1. The scope of the function is the scope of the function, and it will be released when it jumps out
2. The expression scope is an expression application, and the memory that is deleted if the expression exceeds this expression
3. Program scope, the memory released at the end of the program.
It should be noted that although there are these scope restrictions, it is not necessary to use new to pass variables. As long as the internal scope of the variable
Copy to the outer range can be passed. But having said that, the array can not be copied directly, the array name is passed its address, and use
This visit is still the original space, which will cause problems. |
|