In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.