当前位置:网站首页>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;
}
边栏推荐
- Federal learning: dividing non IID samples by Dirichlet distribution
- Cross domain, CORS, jsonp
- 发现mariadb数据库时间晚了12个小时
- Cmake tutorial series -05- options and variables
- High paid programmers & interview questions series 63: talk about the differences between sleep (), yield (), join (), and wait ()
- What is a self signed certificate? Advantages and disadvantages of self signed SSL certificates?
- Visual HTA form designer htamaker interface introduction and usage, Download | HTA VBS visual script writing
- Lua Basics
- What is the concept of string in PHP
- CMake教程系列-01-最小配置示例
猜你喜欢

oracle怎么设置密码复杂度及超时退出的功能

What files does a CA digital certificate contain? How to view SSL certificate information?

Mysql提取表字段中的字符串

HTA入门基础教程 | VBS脚本的GUI界面 HTA简明教程 ,附带完整历程及界面美化

Some configuration details about servlet initial development

Detailed explanation of minimum stack
![[dry goods sharing] the latest WHQL logo certification application process](/img/c3/37277572c70b0af944e594f0965a6c.png)
[dry goods sharing] the latest WHQL logo certification application process

What is the concept of string in PHP

prompt learning 一个空格引发的血案

Linear algebra Chapter 4 Summary of knowledge points of linear equations (Jeff's self perception)
随机推荐
oracle怎么设置密码复杂度及超时退出的功能
Linear algebra Chapter 3 summary of vector and vector space knowledge points (Jeff's self perception)
Cmake tutorial series-03-dependency management
A quick look at the statistical data of 23 major cyber crimes from 2021 to 2022
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.
O & M (20) make and start USB flash disk and install win10
How to set password complexity and timeout exit function in Oracle
Servlet面试题
Cmake tutorial series -04- compiling related functions
Wechat applet page Jump and parameter transfer
What is certificate transparency CT? How to query CT logs certificate logs?
2022 the action of protecting the net is imminent. Things about protecting the net
c#控制台格式化代码
FDA mail security solution
JvxeTable子表记录加载完毕事件
SQLite use
Interrupt operation: abortcontroller learning notes
Global and Chinese markets of liquid optical waveguides 2022-2028: Research Report on technology, participants, trends, market size and share
Detailed explanation of minimum stack
Differences among digicert, SECTIONO and globalsign code signing certificates