当前位置:网站首页>6. Functions of C language, why functions are needed, how functions are defined, and the classification of functions
6. Functions of C language, why functions are needed, how functions are defined, and the classification of functions
2022-07-28 20:05:00 【A programmer who loves playing badminton】
1. Why function is needed
Avoid repetitive operations
It is conducive to the modularization of the program
2. What is a function
logically : A separate block of code that performs a specific function
Physically : Able to receive data , Be able to process the received data , And return the processing result
summary : Function is a tool , It is designed to solve a large number of similar problems
3. How to define a function
The return value of the function Function name ( A list of formal parameters of a function )
{
The body of the function
}
- Function definition The essence It is a specific method to describe in detail why a function can realize a specific function
- return expression ; The meaning of
- Terminate called function , Returns the value of the expression to the calling function
- If the expression is empty , Then terminate the function , Do not return any value to the called function
- break Is used to terminate loops and switch Of ,return Is used to terminate the function
void test_return() { for (int i = 0; i < 5; i++) { printf("the number of circle is %d", i); return; } printf("hello world"); }The result of this code will not appear helloworld, And it will only appear once the number of circle is 0
This is because in the first execution for loop ,return This function has been terminated .
3. The type of the return value of a function is also called the type of the function , So if The return value type before the function name and return expression ; If the type of expression in is different , be The final function return value type The return value type before the function name shall prevail .
int funa()
{
return 10.5; // Because the return value type of the function is int So the final f The return is 10 instead of 10.5;
}4. Classification of functions
There are parametric functions and Nonparametric functions
There are return value functions and No return function
Library function and User defined functions
Ordinary function and The main function (main function )
A program must have and can only have one main function
The main function can call ordinary functions , Ordinary functions cannot call the main function
Ordinary functions can call each other
The main function is the entry and exit of the program
边栏推荐
- Leetcode day4 the highest paid employee in the Department
- [C language] random number generation and `include < time. H > 'learning
- 云原生编程挑战赛火热开赛,51 万奖金等你来挑战!
- Implementation of markdown editor in editor.md
- “中国网事·感动2022”二季度网络感动人物评选结果揭晓
- HSETNX KEY_NAME FIELD VALUE 用法
- What is the process of swing event processing?
- [C language] header file of complex number four operations and complex number operations
- leetcode day3 查找重复的电子邮箱
- Advanced notes (Part 2)
猜你喜欢

Deploy LNMP automatically with saltstack

Advanced notes (Part 2)

利用STM32的HAL库驱动1.54寸 TFT屏(240*240 ST7789V)

editor.md中markdown编辑器的实现

Idea properties file display \u solution of not displaying Chinese
![[C language] print pattern summary](/img/48/d8ff17453e810fcd9269f56eda4d47.png)
[C language] print pattern summary

云计算笔记part.2——应用管理

leetcode day1 分数排名

Tencent cloud deployment lamp_ Experience of building a station

河北邯郸:拓展基层就业空间 助力高校毕业生就业
随机推荐
Thoroughly understand bit operations - shift left, shift right
Basic knowledge of C language
English translation Portuguese - batch English conversion Portuguese - free translation and conversion of various languages
Deploy LNMP automatically with saltstack
High beam software has obtained Alibaba cloud product ecological integration certification, and is working with Alibaba cloud to build new cooperation
Crawl IP
Labelme (I)
Function fitting based on MATLAB
leetcode day4 部门工资最高的员工
MySQL command statement (personal summary)
The results of the second quarter online moving people selection of "China Internet · moving 2022" were announced
中国能否在元宇宙的未来发展中取得突破,占领高地?
Design of air combat game based on qtgui image interface
Hebei: stabilizing grain and expanding beans to help grain and oil production improve quality and efficiency
Leetcode Day1 score ranking
Cloud computing notes part.1 - system management
Sequential linear table - practice in class
Stories of Party members | Li qingai uses cartoons to drive farmers to increase income and become rich
[C language] Pointer elementary knowledge points
C language implementation of strncpy