In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of C language how to define the function, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to define the function in C language. let's take a look.
Start by writing programs:
# include int add (int x, int y) {int z = x + y; return z;} int main () {int a = 1; int b = 2; int c = add (a, b); printf ("c =% d\ n", c); return 0;}
Running result:
C = 3
Program analysis:
(1)
The function definition is in the form of:
Type function name (type form parameter, …... )
{
Function body
}
(2)
Corresponding to our program, we define a function named add, and the type of return value of the function represented by int on the left of add. Corresponds to the type of z returned in the function body.
(3)
X and y are formal parameters, and an and b in main () function an and b are actual parameters.
(4)
The add in the main function is not followed by curly braces, indicating that it is a function call, not a function definition. The specific add function is defined above the main function.
(5)
When the add function is called, the actual parameter (argument) is passed to the formal parameter (formal parameter), so x = a = 1, y = b = 2
(6)
Z = x + y = 1 + 2 = 3
(7)
Int c = add (a, b) indicates that the value obtained by the add function is assigned to c. That is, c = add (1,2) = z = 3. Finally c = 3
This is the end of the article on "how to define functions in C language". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to define functions in C language". If you want to learn more, you are welcome to follow the industry information channel.
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.