当前位置:网站首页>C:什么是函数中的返回值(转)
C:什么是函数中的返回值(转)
2022-07-27 14:25:00 【我滴名痣叫老八】
!!复制自百度网友22971b0!!
简单的说,函数就是一个算法,有不有返回值是跟这个函数做什么的有关系。
一般情况下,求和这类的就要返回值,比如
int add(int a,int b)
{
return a+b; //这就返回a+b的和,用函数的时候,你只要传a,b的值就得了
}
用的时候这样:
int s=add(100,200); //就把100+200也就是300的值赋给s了
这种情况就是相当于你去A地做买东西,你肯定得拿东西回来。你拿回来的东西也就是返回值
-------------------------------------------
还有些不用返回值的,比如,输出,或者给有地址的变量赋值等 这些函数前面就可以用void 表示无返回值,当然你也可以返回你想返回的。比如说成功或者失败返回true or false.也可以随意返回一个int型的 1或者0
比如:
void pri(int i)
{
printf("%d",i); //这个就是打印一个整型的i出来
}
这种就像你去A地不干什么,就去那儿吼两句,也就不用拿什么回来了。
还有种给有地址的变量赋值。那就相当于你去a地寄了一封信,也不用什么什么回来。
啊,打得手累,我就这样理解了。给是清楚点了,呵呵
例如你要计算5+3=?,这个就需要返回值啦,但你要是排列字符之类的,就不需要返回值,因为它是对字符进行操作,没有数字。
边栏推荐
- Inside router of network equipment hard core technology (10) disassembly of Cisco asr9900 (4)
- 魔塔项目中的问题解决
- Network equipment hard core technology insider router chapter Cisco asr9900 disassembly (I)
- Spark lazy list files 的实现
- TCC
- Some binary bit operations
- C language: factorial recursive implementation of numbers
- Unity3d learning note 10 - texture array
- 实现自定义Spark优化规则
- 【剑指offer】面试题51:数组中的逆序对——归并排序
猜你喜欢

Several basic uses of tl431-2.5v voltage reference chip

MySQL interview 40 consecutive questions, interviewer, if you continue to ask, I will turn my face

【剑指offer】面试题50:第一个只出现一次的字符——哈希表查找

Leetcode interview question 17.21. water volume double pointer of histogram, monotonic stack /hard

Digital storage oscilloscope based on FIFO idt7202-12

Singles cup, web:web check in

STL value string learning

Spark 本地程序启动缓慢问题排查

Spark TroubleShooting整理

How to edit a framework resource file separately
随机推荐
Tools - common methods of markdown editor
Go language learning notes (1)
学习Parquet文件格式
Spark 3.0 测试与使用
Leetcode 456.132 mode monotone stack /medium
Network equipment hard core technology insider router Chapter 17 dpdk and its prequel (II)
一文读懂鼠标滚轮事件(wheelEvent)
【剑指offer】面试题46:把数字翻译成字符串——动态规划
华为鸿蒙模拟器去除顶部导航栏方法
Unity性能优化------渲染优化(GPU)之LOD(Level of detail)
DevEco Studio2.1运行项目报错
Spark lazy list files 的实现
Leetcode 781. rabbit hash table in forest / mathematical problem medium
Four kinds of relay schemes driven by single chip microcomputer
修改 Spark 支持远程访问OSS文件
微信公众平台开发概述
Pytorch replaces some components in numpy. / / please indicate the source of the reprint
【剑指offer】面试题49:丑数
Network equipment hard core technology insider router Chapter 6 tompkinson roaming the online world (middle)
Sword finger offer merges two sorted linked lists