当前位置:网站首页>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
边栏推荐
- 串口控制舵机转动
- LeetCode 4. 寻找两个正序数组的中位数(hard)
- A week of short video platform 30W exposure, small magic push helps physical businesses turn losses into profits
- 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
- DGraph: 大规模动态图数据集
- Serial port controls steering gear rotation
- Global and Chinese markets for disposable insulin pumps 2022-2028: Research Report on technology, participants, trends, market size and share
- Summary | three coordinate systems in machine vision and their relationships
- 台积电全球员工薪酬中位数约46万,CEO约899万;苹果上调日本的 iPhone 售价 ;Vim 9.0 发布|极客头条...
- System Verilog实现优先级仲裁器
猜你喜欢
Summary | three coordinate systems in machine vision and their relationships
总结|机器视觉中三大坐标系及其相互关系
Hard core! One configuration center for 8 classes!
DGraph: 大规模动态图数据集
Mathematical analysis_ Notes_ Chapter 6: Riemann integral of univariate function
Mysql database mysqldump why there is no statement to create a database
SSM整合-异常处理器及项目异常处理方案
TCP server communication process (important)
Analyzing more than 7million R & D needs, it is found that these eight programming languages are the most needed in the industry!
忆当年高考|成为程序员的你,后悔了吗?
随机推荐
基于Impala的高性能数仓实践之执行引擎模块
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
618深度复盘:海尔智家的制胜方法论
Data security industry series Salon (III) | data security industry standard system construction theme Salon
数字IC手撕代码--投票表决器
有赞和腾讯云、阿里云一同摘得“中国企业云科技服务商50强”[通俗易懂]
LeetCode 5. 最长回文子串
PWM controlled steering gear
图书管理系统(山东农业大学课程设计)
Penetration tool - intranet permission maintenance -cobalt strike
大廠面試總結大全
Student course selection system (curriculum design of Shandong Agricultural University)
Mysql database mysqldump why there is no statement to create a database
unity Hub 登錄框變得很窄 無法登錄
做机器视觉哪个软件好?
What if the win11 app store cannot load the page? Win11 store cannot load page
LeetCode 6. Zigzag transformation (n-shaped transformation)
[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
TCP congestion control details | 2 background
隐私计算技术创新及产业实践研讨会:学习