当前位置:网站首页>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
边栏推荐
- High beam software has obtained Alibaba cloud product ecological integration certification, and is working with Alibaba cloud to build new cooperation
- Why is there no log output in the telnet login interface?
- [network] communication across regional networks learn how routing tables work
- zfoo增加类似于mydog的路由
- [C language] simulation implementation of pow function (recursion)
- [C language] Pointer advanced knowledge points
- 数字图像理论知识(一)(个人浅析)
- Special draft of Mir | common sense knowledge and reasoning: representation, acquisition and application (deadline on October 31)
- Know small and medium LAN WLAN
- Cdga | how can the industrial Internet industry do a good job in data governance?
猜你喜欢
![[C language] function](/img/81/c185e2bb5eccc13433483f9558f52a.png)
[C language] function

C+ + core programming

河北:稳粮扩豆助力粮油生产提质增效

adb remount of the / superblock failed: Permission denied
![[C language] Hanoi Tower problem [recursion]](/img/d8/ff66928c2bc2ad906e38a360a8cf94.png)
[C language] Hanoi Tower problem [recursion]

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

数字图像理论知识(一)(个人浅析)
![[NPP installation plug-in]](/img/6f/97e53116ec4ebc6a6338d125ddad8b.png)
[NPP installation plug-in]

Deploy ZABBIX automatically with saltstack

Stories of Party members | Li qingai uses cartoons to drive farmers to increase income and become rich
随机推荐
leetcode day3 超过经理收入的员工
Leetcode Day1 score ranking
Find the memory occupied by the structure
Prometheus deployment
HSETNX KEY_NAME FIELD VALUE 用法
Redis notes
Read how to deploy highly available k3s with external database
A chip company fell in round B
C language function
How to write the SQL statement of time to date?
There is a 'single quotation mark' problem in the string when Oracle inserts data
Advanced notes (Part 2)
云计算笔记part.1——系统管理
Redis笔记
Leetcode Day5 delete duplicate email
数字图像理论知识(一)(个人浅析)
毕马威中国:证券基金经营机构信息技术审计项目发现洞察
Labelme(一)
There are five certificates in the soft examination advanced examination, which is more worth taking?
Circular linked list OJ question