当前位置:网站首页>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
边栏推荐
- 使用递归或while循环获取父/子层级结构的名称
- LeetCode 498. 对角线遍历
- Jz2440 - - - utiliser le programme de gravure uboot
- Mysql database field query case sensitive setting
- From TF 1 X to TF 2.6 (update if you encounter it)
- Go learning notes (83) - code specification and common development skills
- online trajectory generation
- 2021-11-12 vrep vision sensor configuration
- Use recursion or a while loop to get the name of the parent / child hierarchy
- [trajectory planning] testing of ruckig Library
猜你喜欢

2021-11-29 quintic polynomial of trajectory planning

Jz2440 - - - utiliser le programme de gravure uboot

A Style-Based Generator Architecture for Generative Adversarial Networks

The basis of C language grammar -- learning of local variables and storage categories, global variables and storage categories, and macro definitions

The 100000 line transaction lock has opened your eyes.

Redis notes (13) - scan and keys search for specific prefix key fields (command format, usage examples, locating large keys)

Custom interceptor

jz2440---使用uboot燒錄程序

深度学习(初识tensorflow2.版本)之三好学生成绩问题(1)

How to create an IE tab in edge browser
随机推荐
Learning to Generalize Unseen Domains via Memory-based Multi-Source Meta-Learning for Person Re-ID
MapReduce & yarn theory
thinkphp6.0的第三方扩展包,支持上传阿里云,七牛云
Specific meaning of go bootstrap
Opencv depthframe - > pointcloud causes segmentation fault!
Single sign on logic
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.)
Throttling, anti chattering, new function, coriolism
Install new version cmake & swig & tinyspline
Leetcode refers to offer II 091 Paint house - modify in place
Jz2440--- using uboot burning program
进入页面输入框自动获取焦点
Jupyter Notebook遇到的问题
Notes on sports planning on November 22, 2021
Badge series 4: use of circle Ci
How about the security of flush stock trading software? How to open an account in flush
install opencv-contrib-dev to use aruco code
thymeleaf中抽取公共片段
Flink入门——单词统计
做测试需要知道的内容——url、弱网、接口、自动化、