当前位置:网站首页>C语言自定义函数的方法
C语言自定义函数的方法
2022-07-02 13:39:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
一、C语言之自定义函数的调用
1.声明一个自定义函数:
void fun(void);//函数的声明
也可在主函数之前编写自定义函数;
2.主函数里调用自定义函数:
int main(void)
{
fun();//调用fun函数;
return 0;
}
3.编写自定义函数的功能:
void fun(void)
{
int a=12;
printf(“a=%d”,a);输出a
}
源代码如下:
#include "stdio.h"
void fun(void);//声明自定义函数
int main(void)//主函数{fun();//调用fun函数 “
return 0;}
void fun(void){int a=12;//定义一个整形常量a=12;printf("a=%d",a);//输出a;}
运行程序结果:
a=12
二、带参数的函数
1,声明一个自定义函数:
void fun(uchar a);
2,调用函数
int main(void)//主函数 { int i; for(i=0;i<8;i++) { fun(i);//调用fun函数 括号里一定要带参数,否则会报错 printf(“\n”);//换行 }
return 0;}
3.编写自定义函数
void fun(char a)// fun函数带一个 char类型的参数 { int i=0; char b=’*’; for(i=8;i>0;i–) printf(“%c”,b);//输出a; }
源程序:
#include "stdio.h"
void fun(char a);//声明自定义函数
int main(void)//主函数{int i;for(i=0;i<8;i++){fun(i);//调用fun函数printf("\n");//换行}
return 0;}
void fun(char a){int i=0;char b='*';for(i=8;i>0;i--)printf("%c",b);//输出a;}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/147813.html原文链接:https://javaforall.cn
边栏推荐
- 台积电全球员工薪酬中位数约46万,CEO约899万;苹果上调日本的 iPhone 售价 ;Vim 9.0 发布|极客头条...
- 数学分析_笔记_第5章:一元微分学
- LeetCode 2. 两数相加
- 大厂面试总结大全
- john爆破出现Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
- 云原生的 CICD 框架:Tekton
- Global and Chinese markets for slotting milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
- 中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
- TypeScript数组乱序输出
- LeetCode 1. Sum of two numbers
猜你喜欢

The login box of unity hub becomes too narrow to log in

Interview summary of large factories

数学分析_笔记_第6章:一元函数的Riemann积分
![john爆破出现Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])](/img/4c/ddf7f8085257d0eb8766dbec251345.png)
john爆破出现Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])

LeetCode 1. Sum of two numbers

电脑管理员权限在哪里可以打开

Summary of monthly report | list of major events of moonbeam in June

Which software is good for machine vision?

DigiCert SSL证书支持中文域名申请吗?

路由模式:hash和history模式
随机推荐
Aike AI frontier promotion (2.15)
Masa framework - DDD design (1)
Unity uses ugui to set a simple multi-level horizontal drop-down menu (no code required)
unity Hub 登录框变得很窄 无法登录
[error record] the connection of the flutter device shows loading (disconnect | delete the shuttle/bin/cache/lockfile file)
Win11应用商店无法加载页面怎么办?Win11商店无法加载页面
隐私计算技术创新及产业实践研讨会:学习
SSM整合-异常处理器及项目异常处理方案
Hard core! One configuration center for 8 classes!
Student course selection system (curriculum design of Shandong Agricultural University)
PWM controlled steering gear
路由模式:hash和history模式
Global and Chinese markets for carbon dioxide laser cutting heads 2022-2028: Research Report on technology, participants, trends, market size and share
Mathematical analysis_ Notes_ Chapter 5: univariate differential calculus
go-zero微服务实战系列(八、如何处理每秒上万次的下单请求)
Multi task prompt learning: how to train a large language model?
Seal Library - installation and introduction
什么是泛型?- 泛型入门篇
Summary | three coordinate systems in machine vision and their relationships
七一献礼:易鲸捷 “百日会战”完美收官 贵阳银行数据库提前封板