In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to define the pointer of C language". In the daily operation, I believe that many people have doubts about how to define the pointer of C language. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the question of "how to define the pointer of C language"! Next, please follow the editor to study!
The irreversibility of function parameter transmission when we need to frequently use a piece of code to calculate the triangle area, then the code snippet that implements this function can be packaged into a function and provided to other code calls. Such as "float triangle_area (float base, float height)", in this function, "triangle_area" is the function name, it is a function that returns the type "float", and the "float base" and "float height" in parentheses are used to pass the parameters of the triangle into the function, which we call "formal parameters" or "pass parameters". When other code needs to solve the area of a triangle, just call "triangle_area". Once this function is called, the program will immediately jump to the triangle area solving code to calculate, after the calculation is completed, the triangle area will be returned in the form of "float". The so-called return value, that is, after the completion of the function operation to return a value of the result, a function can only return at most one return value, we only need to define a variable in the function with the same type of function, store the operation result in it, and use the "return" keyword to return it. The function for solving the triangle area is shown in figure 6-1-1. Figure 6-1-1 triangular area function review the above content, while the memory is relatively fresh, let's use C language to solve a problem. Suppose Xiao Ming and Xiao Li are a pair of good friends. Xiao Ming has a cup of caramel macchiato in his hand. Xiao Li has a cup of double milk tea in his hand. They each drank half a cup, and each wanted to taste the taste of the drink in each other's hands. It was a very simple thing to exchange it. But they do not want their cups to be drunk by each other, so they can only exchange the drinks in the cups. Please help them design a function to exchange the drinks in the cups. This is actually a very simple variable content exchange problem, just need to find another cup, pour Xiao Ming's drink into it, then pour Xiao Li's drink to Xiao Ming, and finally pour Xiao Ming's drink to Xiao Li in the third cup, we can easily complete this function, as shown in figure 6-1-2.
Figure 6-1-2 swap the drinks in the cup
After Xiao Ming and Xiao Li saw the algorithm, they did not want to pour the drink, so they deadlocked. They came up with a way to give it to Xiao Ming's grandmother to complete the function of exchanging drinks. At this time, Xiao Ming's grandmother is equivalent to this specific module of beverage exchange, which we can associate as a function in C language. When Xiao Ming's drink and Xiao Li's drink are passed to grandma, it is equivalent to passing the parameters to the function. So we can write the code in figure 6-1-3.
Figure 6-1-3 variable exchange function
Looking closely at the output value of the code in figure 6-1-3, we were surprised to find that the function did not achieve the desired results. The drinks in Xiao Ming's cup and Xiao Li's cup were still not exchanged. I read the code carefully and found no problems. This is really not caused by a code problem. To borrow the above story, there is an important feature about function calls that we should pay attention to, that is, the function transfer parameters are passed one-way, no matter how the formal parameters are changed in the function, the value of the parameters passed at the calling function is not affected at all. This must be noted. The only way the function can pass the result to the main function is to return the value, but the return value of the function is the only one. This is similar to the fact that grandma saw two dolls tossing the drinks in the cup back and forth unsanitary and unwilling to exchange them. So is there nothing we can do about the above question? To continue our story, just at this time, the passing Uncle Wang came and saw that everyone was sad and went up to inquire about the situation. after learning about the situation, Uncle Wang found that the two cups were exactly the same, and there was a bladder inside each cup. You just need to unscrew the inner tank and exchange it. Finally, everyone was happy and went back to their homes. We can write the code shown in figure 6-1-4.
Figure 6-1-4 use pointers to exchange values in variables. At this point, the study of "how to define pointers in C language" is over. I hope you can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.