In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
This article uses easy-to-understand examples to introduce what are the ways of function parameters, the code is very detailed, interested friends can refer to, I hope it can be helpful to you.
The main results are as follows: 1. The formal parameter and the actual parameter each occupy an independent space when passing by value.
2. Address transmission is to send the storage address of the actual parameter to the parameter.
3. Reference passing is an alias with reference as argument, which is the same variable as argument.
Sample code
Pass by value
# includevoid swap1 (int x, int y) / / the xpeny variable in the definition is the two formal parameters of the swap function {int tmp; tmp = x; x = y; y = tmp; printf ("x% d direction y% d\ n", x Magi y);} int main () {int a = 2; int b = 3; swap1 (a, b) / / the return b variable is the actual parameter printf of the swap function ("a moment% d direction banner% d", a moment b); return 0;}
Address delivery
Void swap2 (int * px, int * py) {int tmp; tmp = * px; * px= * py; * py= tmp; printf ("px=%d,py=%d\ n", * px, * py);} int main () {int a = 2; int b = 3; swap2 (& a, & b) / * the swap function is called, and there is also an implied action px=&a;py=&b;*/ printf ("averse% ddirection baked% d", a, b); return 0;}
Reference transfer
# includevoid swap3 (int & x int int & y) {int tmp = x; x = y; y = tmp; printf ("x% d direction yearly% d\ n", x, y);} int main () {int a = 2; int b = 3; swap3 (a, b); / / the call method is the same as the value passed printf ("aversion% ddirection b% d", a, b) System ("pause"); return 0;} about the way the function parameters are shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.