当前位置:网站首页>C语言进阶第43式:函数的意义
C语言进阶第43式:函数的意义
2022-04-21 15:31:00 【东川君】
C语言中的函数
函数的由来

模块化程序设计

C语言中的模块化

面向过程的程序设计
面向过程是一种以过程为中心的编程思想;
首先将复杂的问题分解为一个个容易解决的问题;
分解过后的问题可以按照步骤一步步完成;
函数是面向过程在C语言中的体现;
解决问题的每个步骤可以用函数来实现;
声明和定义

声明的意义在于告诉编译器程序单元的存在;
定义则明确指示程序单元的意义;
C语言中通过extern进行程序单元的声明;
一些程序单元在声明时可以省略extern;

#include <stdio.h>
#include <malloc.h>
extern int g_var;
extern struct Test;
int main()
{
extern void f(int i, int j);
extern int g(int x);
struct Test* p = NULL; // (struct Test*)malloc(sizeof(struct Test));
printf("p = %p\n", p);
//g_var = 10;
printf("g_var = %d\n", g_var);
f(1, 2);
printf("g(3) = %d\n", g(3));
free(p);
return 0;
}
//global.c//
#include <stdio.h>
int g_var = 10;
struct Test
{
int x;
int y;
};
void f(int i, int j)
{
printf("i + j = %d\n", i + j);
}
int g(int x)
{
return (int)(2 * x + g_var);
}
小结
函数是面向过程思想在C语言中的体现;
面向过程是由上至下分解问题的设计方法;
程序中的定义和声明完全不同;
C语言中通过extern对程序单元进行声明;
版权声明
本文为[东川君]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Bruce_Qee/article/details/124319870
边栏推荐
猜你喜欢

【常见问题】anaconda prompt报错solving environment:failed

外贸公司一般用什么邮箱,电子邮件如何群发?

客户端邮件同步到webmail如何操作,电子邮件地址怎么注册?

Acwing 1775 Lost cattle (simulated)

许远东受邀上海管理科技论坛做《LTD数字化经营方法论》分享

Solution de transformation de mot de données de 111 pages Fine Chemical Co., Ltd.

Jetpack compose uses custom operators to achieve the effect of drawing five pointed stars

Obsidian automatically uploads pictures to the drawing bed - install picgo plug-in and configure

AcWing 1854. Promotion count (Analog)

Simple explanation of impermanence loss
随机推荐
全国降雨侵蚀力因子R值
Take it easy, just talk about the soft test
小程序简介和开发工具
JUC concurrent learning notes
50页京东云·睿擎-打造企业数字化转型的敏捷引擎业务中台解决方案
读书破万“卷”:国民阅读洞察2022
【unity笔记】L3Unity Shader学习开始
mysql数据库字段上下移动
AcWing1800. Do not do the last (enumeration)
Jetpack compose uses custom operators to achieve the effect of drawing five pointed stars
What is an email address? Easy to use email registration application
APP评测的网站有哪些?
返璞归真,多方安全计算要回归到“安全”的本源考虑
On the import and export of browser bookmarks
Deltix Round, Summer 2021 E. Equilibrium
企业邮箱怎么登录?企业邮箱登录方法
111页精细化工股份公司数据字转型解决方案
LeetCode 654:最大二叉树
Solve i.mx6u driver transplantation LED flashing
Huawei power PON distribution network solution