#include
Void free (int I) { If (I.=0) i=0; } Int main () { Int I, [5] a={1, 2, 3, 4, 5}; Free (a [2]); I=a, [2]. Printf (" % d \ n ", I); } The result is 3, why is not zero? Parameters and arguments of knowledge? CodePudding user response:
As parameter arguments of knowledge (parameter is a copy of the argument), involving preach value and the address of the knowledge CodePudding user response:
Because I was free in the function of the local variable, rather than global or variables in the main function, the value of the local variable cannot I=0 to the main function, CodePudding user response:
1/f, said makes sense, it is a question of value to pass or address, you can change Void free (int * p) { If (* p!=0) { * p=0; } } CodePudding user response:
reference 2 building self-confidence boy reply: because I was free in the function of the local variable, rather than global or variables in the main function, the value of the local variable cannot I=0 to the main function, If this is the case then? #include Void free (int m) { If (m!=0) M=0; } Int main () { Int I, [5] a={1, 2, 3, 4, 5}; Free (a [2]); I=a, [2]. Printf (" % d \ n ", I); } CodePudding user response:
refer to Hans - 123-4 floor response: Quote: refer to the second floor confident boy reply: of a local variable in a function because I was free, rather than global or variables in the main function, the value of the local variable cannot I=0 to the main function, If this is the case then? #include Void free (int m) { If (m!=0) M=0; } Int main () { Int I, [5] a={1, 2, 3, 4, 5}; Free (a [2]); I=a, [2]. Printf (" % d \ n ", I); } The m is not in the same, free of m in the main, the parameter m in the free of a local variable in a function is free, but you can do it: void free (int * m) { If (* m!=0) * m=0; } This definition free, namely the argument addresses to free, CodePudding user response:
https://blog.csdn.net/yinzewen123/article/details/80532886? Ops_request_misc=% 257 b % 2522 request 2522% % 255 fid % 253 a 2522% % 2522% % 2522159920883319725222423450% % 2522 SCM 252 c 253 a % 252220140713.130102334 PC % 255 fall. The 2522% % 257 d & amp; Request_id=159920883319725222423450 & amp; Biz_id=0 & amp; Utm_medium=distribute. Pc_search_result. None - task - blog - 2 ~ all ~ first_rank_ecpm_v3 ~ pc_rank_v3-3-80532886. Pc_ecpm_v3_pc_rank_v3 & amp; E5 utm_term=% 95% % 87% % % E6 BD B0 E8 8 d B8 E4 % % % % % 83% % BD E8 E5 % BF % 94% % 9 b % 9 A0 e % E6 % % 88% E5 E9 8 f % 98% % 87% % E7 8 f % % a % 84% % E6 8 of 9 E9 c % 87% % 92% 88 & amp; SPM=1018.2118.3001.4187 You can take a look at this link, the most basic should be the cause of the stack memory CodePudding user response:
Void free (int I) { If (I.=0) i=0; } function calls out, variable I statement cycle will be over, because I was stack memory variables, so after use is unknown, CodePudding user response:
In c + +, reference can be used directly, and others don't move,,, Void free (int & amp; M) { If (m!=0) M=0; }