当前位置:网站首页>The basis of C language grammar -- function definition learning
The basis of C language grammar -- function definition learning
2022-06-26 09:52:00 【Tanzanian auduvi Canyon expert】
Function definition :
Function from English function Translated from ,function It translates to function , It's also a function , In essence , Functions are collections used to complete certain functions .
Why use functions
For example , In a long piece of code , There are many businesses , Many places need to calculate the monthly sales of goods , They all realize the same function , Is every business , Each place writes its own set of query and calculation logic , In this way, the code is very redundant and complicated , Then we can package this code , Let it stand alone , Function encapsulation is also used , such , everyone , If every business wants to use this function , Just one sentence to call , It's like I say a word to you , I want to use the function named so and so , I transferred him , Then he will be used by me .
Defining a function should include the following :
(1) Specify the name of the function , To call by name later .
(2) Specifies the type of function , That is, the type of function return value .
(3) Specifies the name and type of the function's arguments , To pass data to functions when they are called , This is not required for nonparametric functions .
(4) Specifies what the function should do , That is, what functions do , The function of a function . That's the most important thing , It is solved in the function body .
Function definition method
// Mode one Parameterless function
Type name Function name (){
// The type name defines the type according to the type of the return value of the function
The body of the function
}
// Mode two Parameterless function
Type name Function name (void){
// void It means empty , Indicates that the function has no parameters
The body of the function
}
// Mode three Parameterless function
void Function name (){
The body of the function
}
// Mode 4 There are parametric functions
Type name Function name ( Formal parameter table column ){
The body of the function
}
// Parameterless function
#include<stdio.h>
int main()
void print _ star();// Statement print _ star function
void print _ message();// Statement print _ message function
print _ star();/ call print _ star function
print _ message();//print _ message function
print _ star();// call print _ star function
return 0;
)
void print _ star()// Definition print _ star function ; The type is void Function of , There is no need for return Return value
{
print[('******************\n');// Output one line × Number
}
void print _ message()// Definition print _ message function
(printf(”How do you do!\n");// Output a line of text
)
Running results :
How do you do?
*******************
// There are parametric functions
int max(int x, int y){
// here x、y It's a parameter
int sum; // Declaration part
sum=x+y; // Execute statement part
return sum;
}
// call
int max(a, b) // here a、b Is the argument
边栏推荐
- Getting started with Flink - word statistics
- Code statistics tools cloc and SCC
- LeetCode 498. Diagonal traversal
- Meaning of go runtime
- Deep learning (tentsorflow2. version) three good student performance problems (1)
- 欧冠比赛数据集(梅西不哭-离开巴萨也可能再创巅峰)
- Basic grammar of C language -- pointer (character, one-dimensional array) learning
- Several connection query methods of SQL (internal connection, external connection, full connection and joint query)
- Druid data source for background monitoring
- c语言语法基础之——函数嵌套、递归 小程序斐波那契之和、阶乘
猜你喜欢

【CVPR 2021】DatasetGAN: Efficient Labeled Data Factory with Minimal Human Effort

WGCLOUD的web ssh服务端口是多少

2021-11-29 quintic polynomial of trajectory planning

c语言语法基础之——局部变量及存储类别、全局变量及存储类别、宏定义 学习
How to correctly open the USB debugging and complete log functions of Huawei mobile phones?

logback

jz2440---使用uboot烧录程序

逻辑英语结构【重点】

2021年全国职业院校技能大赛(中职组)网络安全竞赛试题(1)详细解析教程

Summary of common commands of vim
随机推荐
Flutter's brain map notes are easy to find and search!
2021-11-12 vrep视觉传感器配置
从tf 1.x到tf 2.6(遇到的就过来更新更新)
欧冠比赛数据集(梅西不哭-离开巴萨也可能再创巅峰)
The third-party extension package of thinkphp6.0 supports uploading to Alibaba cloud and qiniu cloud
Druid data source for background monitoring
What you need to know to test -- URL, weak network, interface, automation
Redis notes (16) - info instructions and command line tools (view memory, status, number of client connections, monitoring server, scan large keys, sampling server, execute batch commands, etc.)
QPM performance monitoring components - General
同花顺炒股软件安全性怎样?在同花顺怎么开户
Abnormal record-23
thymeleaf中抽取公共片段
install realsense2: The following packages have unmet dependencies: libgtk-3-dev
做测试需要知道的内容——url、弱网、接口、自动化、
Comparison of similar PMS in QPM
使用递归或while循环获取父/子层级结构的名称
Click the mask layer to close the pop-up window
Badge series 7: use of codacy
MapReduce&Yarn理论
pcl install