当前位置:网站首页>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
边栏推荐
- Mysql database mysqldump why there is no statement to create a database
- Unity Json 编写
- 国内比较好的OJ平台[通俗易懂]
- LeetCode 3. 无重复字符的最长子串
- &lt;四&gt; H264解码输出yuv文件
- Global and Chinese market of oil analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
- [fluent] dart data type list set type (define set | initialize | generic usage | add elements after initialization | set generation function | set traversal)
- VMware安装win10镜像
- 台积电全球员工薪酬中位数约46万,CEO约899万;苹果上调日本的 iPhone 售价 ;Vim 9.0 发布|极客头条...
- LeetCode 1. 两数之和
猜你喜欢

LeetCode 1. 两数之和

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

Masa framework - DDD design (1)

TCP congestion control details | 2 background

pwm呼吸燈

LeetCode 2. Add two numbers

LeetCode 2. 两数相加

A week of short video platform 30W exposure, small magic push helps physical businesses turn losses into profits

TCP拥塞控制详解 | 2. 背景
![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])
随机推荐
SSM整合-异常处理器及项目异常处理方案
外企高管、连续创业者、瑜伽和滑雪高手,持续迭代重构的程序人生
How to solve the failure of printer driver installation of computer equipment
PCL point cloud image transformation
Masa framework - DDD design (1)
大厂面试总结大全
Global and Chinese markets of stainless steel surgical suture 2022-2028: Research Report on technology, participants, trends, market size and share
PCL least median square method fitting plane
Yyds dry goods inventory # look up at the sky | talk about the way and principle of capturing packets on the mobile terminal and how to prevent mitm
Classic quotations
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 deep resumption: Haier Zhijia's winning methodology
Recalling the college entrance examination and becoming a programmer, do you regret it?
Global and Chinese market of switching valves 2022-2028: Research Report on technology, participants, trends, market size and share
False summer vacation
Mathematical analysis_ Notes_ Chapter 5: univariate differential calculus
Aujourd'hui dans l'histoire: Alipay lance le paiement par code à barres; La naissance du père du système de partage du temps; La première publicité télévisée au monde...
MySQL min() finds the minimum value under certain conditions, and there are multiple results
LeetCode 4. Find the median (hard) of two positive arrays
Yyds dry inventory KVM new inventory to expand space for home