当前位置:网站首页>C语言程序设计之函数的构造
C语言程序设计之函数的构造
2022-04-23 17:12:00 【wx625ea460982ad】
构造函数的目的:为了简化程序和使得你的程序更容易被他人理解
什么情况下推荐构造函数:当程序中的某一功能需要多次使用且实现的代码较长时,就推荐提前构造函数
怎么构造函数:简单来说,你想实现什么功能,就构造什么样的函数
比如:我想实现两个数的相加。程序如下:
#include<stdio.h>
int ADD (intx,inty)
{ int z=x+y;
return z;
}
int main()
{ int a=10;
int b=20;
int sum =0;
sum=ADD(a,b);
printf("%d\n",sum);
return 0;
|从这段程序中我们就可以看到,我想实现两个数的加减,那么我就在main函数之间提前定义一个ADD函数,让它的功能就是完成两个数的相加,然后在主程序中直接去调用这个函数就可以了。
版权声明
本文为[wx625ea460982ad]所创,转载请带上原文链接,感谢
https://blog.51cto.com/u_15607564/5248621
边栏推荐
- ClickHouse-数据类型
- 【解决报错】Error in v-on handler: “TypeError: Cannot read property ‘resetFields’ of undefined”
- ClickHouse-表引擎
- Deep understanding of control inversion and dependency injection
- About stream flow, write it down briefly------
- Further optimize Baidu map data visualization
- Self use learning notes - connected and non connected access to database
- Handwritten event publish subscribe framework
- SPC introduction
- Detailed explanation of C webpai route
猜你喜欢
Detailed explanation of Milvus 2.0 quality assurance system
Shell script -- shell programming specification and variables
oracle 中快速获取表的列名列表
SQL database
Signalr can actively send data from the server to the client
VLAN advanced technology, VLAN aggregation, super VLAN, sub VLAN
[PROJECT] small hat takeout (8)
Deep understanding of control inversion and dependency injection
线性代数感悟之2
Nacos + aspnetcore + Ocelot actual combat code
随机推荐
Nodejs installation and environment configuration
Zhimeng dedecms security setup Guide
Clickhouse - data type
Preliminary understanding of promse
How to implement distributed locks with redis?
oracle 中快速获取表的列名列表
Paging SQL
Use of Shell sort command
Generation of barcode and QR code
Use of shell cut command
BUG_ me
ASP. Net core configuration options (Part 2)
org. apache. parquet. schema. InvalidSchemaException: A group type can not be empty. Parquet does not su
1-4 configuration executable script of nodejs installation
EF core in ASP Generate core priority database based on net entity model
Lock锁
Promise (IV)
【WPF绑定3】 ListView基础绑定和数据模板绑定
[C] thoroughly understand the deep copy
VsCode-Go