当前位置:网站首页>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
边栏推荐
- [C language] scanf format input and modifier summary
- 时间转日期的sql语句应该怎么写?
- [C language] guessing numbers game [function]
- [NPP installation plug-in]
- English translation Italian - batch English translation Italian tools free of charge
- C language array and bubble sort
- 【NPP安装插件】
- MySQL command statement (personal summary)
- C language pointer and two-dimensional array
- Array method added in ES6
猜你喜欢

Intermediate soft test (system integration project management engineer) high frequency test site

Deploy ZABBIX automatically with saltstack

Rand function generates pseudo-random numbers
![[C language] function](/img/81/c185e2bb5eccc13433483f9558f52a.png)
[C language] function

Edge detection and connection of image segmentation realized by MATLAB

Information management system and games based on C language
![[C language] guessing numbers game [function]](/img/db/8ebdb02f137878224367503b730803.png)
[C language] guessing numbers game [function]

Function fitting based on MATLAB

JS batch add event listening onclick this event delegate target currenttarget onmouseenter OnMouseOver

一文读懂如何部署具有外部数据库的高可用 K3s
随机推荐
C+ + core programming
数字图像理论知识(一)(个人浅析)
[C language] Fibonacci sequence [recursion and iteration]
[experience] some suggestions and experience on repairing electronic equipment
C language implementation of strncpy
Getting started with enterprise distributed crawler framework
leetcode day4 部门工资最高的员工
Implementation of strstr in C language
String中常用的API
中国能否在元宇宙的未来发展中取得突破,占领高地?
Implementation of memcpy in C language
Can China make a breakthrough in the future development of the meta universe and occupy the highland?
Integration and implementation of login click graphic verification code in personal blog system
个人博克系统登录点击图形验证码的集成与实现
[C language] step jumping problem [recursion]
[C language] shutdown game [loop and switch statement]
Android section 13 03xutils detailed explanation of database framework (addition, deletion and modification)
软考中级(系统集成项目管理工程师)高频考点
Basic usage of docker
党员故事|李青艾用漫画带动农民增收致富