Transferred from: http://www.cnblogs.com/sxmcACM/p/4127114.html
1. Let's start by talking about the function's copy mechanism
See a simple code
1 # include<stdio.h>2 # Include<stdlib.h>34int Add (int N,IntM{ 6 int z = n + M; 7 return< Span style= "color: #000000;" > Z; } 9 10 int main () 11 {12 printf (%d\n< Span style= "color: #800000;" > ", add (1, 213}
When the function returns, the memory is recycled and the value can still be printed, because the function's copy mechanism
2. A copy of the structure
1 # include<stdio.h>2 # Include<stdlib.h>34structMyStruct5{6int a[5];7IntN8};910void Change (structMyStruct my1)11{MY1.N =0;my1.a[0] =1000;printf ("%d\n", &MY1);15}1617IntMain1 ()18{19struct MyStruct my1 = {{1,2,3,4,5},100};printf ("%d,%d\n0< Span style= "color: #000000;" >], MY1.N); 21 printf (%d\n ", &my1); 22 %d,%d\n" My1.a[0 System ( "pause" Span style= "color: #000000;" >); 25}
Result: (can be found without change, address different)
Conclusion:
1. Except that the array does not have a copy mechanism, all others have a copy mechanism
2. Structure has a copy mechanism
3. Even if there is an array in the struct, there is a copy mechanism
4. Structure array, single copy mechanism
About the replica mechanism