当前位置:网站首页>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
边栏推荐
- Interview summary of large factories
- Leetcode1380: lucky numbers in matrix
- Headline | Asian control technology products are selected in the textile and clothing industry digital transformation solution key promotion directory of Textile Federation
- LeetCode 3. 无重复字符的最长子串
- Global and Chinese markets for slotting milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets for disposable insulin pumps 2022-2028: Research Report on technology, participants, trends, market size and share
- Typescript array out of order output
- Today in history: Alipay launched barcode payment; The father of time-sharing system was born; The first TV advertisement in the world
- Exploration and practice of integration of streaming and wholesale in jd.com
- 总结|机器视觉中三大坐标系及其相互关系
猜你喜欢

头条 | 亚控科技产品入选中纺联《纺织服装行业数字化转型解决方案重点推广名录》

The median salary of TSMC's global employees is about 460000, and the CEO is about 8.99 million; Apple raised the price of iPhone in Japan; VIM 9.0 releases | geek headlines

LeetCode 1. 两数之和
![[North Asia data recovery] data recovery case of raid crash caused by hard disk disconnection during data synchronization of hot spare disk of RAID5 disk array](/img/51/f9c1eed37794db8c8d0eefd60b9e3d.jpg)
[North Asia data recovery] data recovery case of raid crash caused by hard disk disconnection during data synchronization of hot spare disk of RAID5 disk array

Day 18 of leetcode dynamic planning introduction

流批一体在京东的探索与实践

电脑设备打印机驱动安装失败如何解决

忆当年高考|成为程序员的你,后悔了吗?

LeetCode 2. 两数相加

Lampe respiratoire PWM
随机推荐
历史上的今天:支付宝推出条码支付;分时系统之父诞生;世界上第一支电视广告...
Recalling the college entrance examination and becoming a programmer, do you regret it?
LeetCode 5. 最长回文子串
Seal Library - installation and introduction
[error record] the connection of the flutter device shows loading (disconnect | delete the shuttle/bin/cache/lockfile file)
La boîte de connexion du hub de l'unit é devient trop étroite pour se connecter
Sim2real environment configuration tutorial
Global and Chinese market of jacquard looms 2022-2028: Research Report on technology, participants, trends, market size and share
sql解决连续登录问题变形-节假日过滤
Unity uses ugui to set a simple multi-level horizontal drop-down menu (no code required)
Win11应用商店无法加载页面怎么办?Win11商店无法加载页面
618 reprise en profondeur: la méthode gagnante de la famille Haier Zhi
月报总结|Moonbeam6月份大事一览
深度学习图像数据自动标注[通俗易懂]
数字IC手撕代码--投票表决器
分析超700万个研发需求发现,这8门编程语言才是行业最需要的!
LeetCode 2. Add two numbers
Mysql database mysqldump why there is no statement to create a database
Privacy computing technology innovation and industry practice seminar: Learning
Bib | graph representation based on heterogeneous information network learning to predict drug disease association