当前位置:网站首页>Functions in C language
Functions in C language
2022-06-30 02:56:00 【@sen】
Let's give you an example
#include<stdio.h>
void print_C(); // Declaration of functions , Statement statement , There's a semicolon behind it
void print_C() // Definition of function
{
printf(" ###### \n");
printf("## ##\n");
printf("## \n");
printf("## \n");
printf("## \n");
printf("## ##\n");
printf(" ###### \n");
}
int main()
{
print_C(); // Function call
printf("\n");
print_C();
printf("\n");
print_C();
return 0;
} One 、 Definition of function :
Type name Function name ( parameter list ) It is usually named with the corresponding function
( The return value of the function , If you do not need to return, use void)
{
The body of the function
}
Two 、 Declaration of functions
The so-called declaration (Declaration), Just tell the compiler that I want to use this function , It doesn't matter that you haven't found its definition now , Please don't make mistakes , I'll fill in the definition later .
As in the above example , If you don't write a function declaration , The compiler may report errors
3、 ... and 、 Parameters and return values of functions
eg:1、 Write a function sum, Input parameters by the user n, Calculation 1+2+3+....+(n-1)+n And return .
#include<stdio.h>
int sum(int n);
int sum(int n) // Formal parameters , Define a function sum
{
int result = 0;
do
{
result += n;
} while (n-- > 0);
return result;
}
int main()
{
int n, result;
printf("input the value of n:\n");
scanf("%d", &n);
result = sum(n); // The actual parameter
printf("1+2+3+4+...+(n-1)+n The result is :%d\n", sum(n));
return 0;
}2、 Write a function max, Receive two integer parameters , And return the larger of them .
#include<stdio.h>
int max(int, int); // You don't have to define , Just state the type
int max(int x, int y) // Must be defined x,y
{
if (x > y)
return x; // If x>y, return x Value
else
return y;
}
int main()
{
int a, b, c;
printf(" Please enter two integers :");
scanf("%d,%d", &a, &b);
c=max(a, b);
printf(" The larger of them is :%d\n", c);
return 0;
}
边栏推荐
- High paid programmers & interview questions series 63: talk about the differences between sleep (), yield (), join (), and wait ()
- CMake教程系列-05-选项及变量
- Global and Chinese market of relay lens 2022-2028: Research Report on technology, participants, trends, market size and share
- Xunwei enzhipu ITop - imx6 Development Platform
- Azure developer news flash list of events of developers in June
- Raki's notes on reading paper: Leveraging type descriptions for zero shot named entity recognition and classification
- 2. < tag dynamic programming and 0-1 knapsack problem > lt.416 Split equal sum subset + lt.1049 Weight of the last stone II
- Distributed file storage system fastdfs hands on how to do it
- Customize the buttons of jvxetable and the usage of $set under notes
- Intel hex, Motorola S-Record format detailed analysis
猜你喜欢

Cmake tutorial series -02- generating binaries using cmake code

Linear algebra Chapter 3 summary of vector and vector space knowledge points (Jeff's self perception)

Mysql提取表字段中的字符串

How to prevent duplicate submission under concurrent requests
![[dry goods sharing] the latest WHQL logo certification application process](/img/c3/37277572c70b0af944e594f0965a6c.png)
[dry goods sharing] the latest WHQL logo certification application process

How to modify and add fields when MySQL table data is large

How to use vant to realize data paging and drop-down loading

A quick look at the statistical data of 23 major cyber crimes from 2021 to 2022

最小栈详解

Detailed explanation of minimum stack
随机推荐
What kind of foreign exchange trading platform is regulated and safe?
FAQs for code signature and driver signature
Unity TimeLine 数据绑定
Interrupt operation: abortcontroller learning notes
Unity timeline data binding
发现mariadb数据库时间晚了12个小时
002 color classification
Some technology sharing
&nbsp;与空格的区别
Raki's notes on reading paper: discontinuous named entity recognition as maximum clique discovery
What files does a CA digital certificate contain? How to view SSL certificate information?
怎么利用Redis实现点赞功能
Enlightenment from the revocation of Russian digital certificate by mainstream CA: upgrade the SSL certificate of state secret algorithm to help China's network security to be autonomous and controlla
Pytoch learning (II)
How to prevent duplicate submission under concurrent requests
公司电脑强制休眠的3种解决方案
Call collections Sort() method, compare two person objects (by age ratio first, and by name ratio for the same age), and pass lambda expression as a parameter.
2022护网行动在即,关于护网的那些事儿
Summary of interview and Employment Questions
重磅来袭--UE5的开源数字孪生解决方案