当前位置:网站首页>6. 函数
6. 函数
2022-06-21 12:06:00 【我想要去航海】
6.1 概述
作用:将一段经常使用的代码封装起来,减少重复代码。一个较大的程序,一般分为若干个程序块,每个模块实现特定的功能。
6.2 函数的定义
函数定义一般主要有5个步骤:
1. 返回值类型
2. 函数名
3. 参数列表
4. 函数体语句
5. return表达式
6.3 函数的调用
功能:使用定义好的函数。
语法:函数名(参数)
6.4 值传递
所谓值传递,就是函数调用时实参将数值传入给形参。
值传递时,如果形参发生改变,并不会影响实参。
6.5 函数的常见样式
常见的函数样式有4种:
1. 无参无返
2. 有参无返
3. 无参有返
4. 有参有返
6.5 函数的声明
作用:告诉编译器函数名称以及如何调用函数。函数的实际主体可以单独定义。函数的声明可以多次,但是函数的定义只能有一次。
6.6 函数的分文件编写
作用:让代码更加清晰。
函数分文件编写一般有4个步骤:
1. 创建后缀名为.h的头文件
2. 创建后缀名为.cpp的头文件
3. 在头文件中写函数的声明
4. 在源文件中写函数的定义
边栏推荐
- PCB电路板设计都有哪些注意事项?
- findpanel的相关代码
- Ansible 配置首次ssh免认证的操作说明
- Brief discussion on four full bonding processes of oca\uv-oca loca\sloca
- Understand Flink operatorchain object reuse
- Nanjing University static program analyses -- Introduction learning notes
- STM32cubeMX之 uart问题汇总
- The difference between knowing and understanding
- 2022年138套数学分析高等代数考研真题参考解答勘误
- Redis maximum memory elimination strategy
猜你喜欢

华为云发布桌面IDE-CodeArts

SDCC编译器 + VSCode开发 8位微控制器

i. MX - rt1052 SPI and I2C interfaces

HMS core machine learning service ID card identification function to achieve efficient information entry

Apache shardingsphere 5.1.2 release | new driving API + cloud native deployment to create a high-performance data gateway

i.MX - RT1052 SPI和 I2C接口

External-Attention-tensorflow(更新中)

uniapp中常用到的方法(部分) - 时间戳问题及富文本解析图片问题

【云原生 | Devops篇】Jenkins安装与实战(二)

1108. IP address invalidation
随机推荐
Adapter power supply automatic test equipment | introduction to charger ATE test system nsat-8000
Redis-bitmap 位图
Heavyweight, mapstruct 1.5 was released. This time, it finally supports the transformation of map into bean!
Understand Flink operatorchain object reuse
i. MX - rt1052 boot start
STM32cubeMX之 uart问题汇总
Apache shardingsphere 5.1.2 release | new driving API + cloud native deployment to create a high-performance data gateway
Creation mode - singleton mode
SSD的anchor_box计算
i. MX - rt1052 SPI and I2C interfaces
Golang implements redis (9): use geohash to search people nearby
搭建zabbix监控及邮件报警
动手学数据分析 数据可视化
2-zabbix automatically add hosts using autodiscover
Understand UML class diagram and sequence diagram
[untitled]
Formation harmonyos I
Nanjing University static program analyses -- Introduction learning notes
Codeforces Round #797 (Div. 3) F. Shifting String题解
版本号命名规范