当前位置:网站首页>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
边栏推荐
- Global and Chinese market of discharge machines 2022-2028: Research Report on technology, participants, trends, market size and share
- Mathematical analysis_ Notes_ Chapter 5: univariate differential calculus
- 串口控制舵机转动
- 路由模式:hash和history模式
- ⌈ 2022 ⌋ how to use webp gracefully in projects
- Day 18 of leetcode dynamic planning introduction
- Global and Chinese markets for slotting milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
- SSM integration exception handler and project exception handling scheme
- 什么是泛型?- 泛型入门篇
- 分析超700万个研发需求发现,这8门编程语言才是行业最需要的!
猜你喜欢
PWM breathing lamp
Seal Library - installation and introduction
Machine learning perceptron model
Headline | Asian control technology products are selected in the textile and clothing industry digital transformation solution key promotion directory of Textile Federation
What is normal distribution? What is the 28 law?
A week of short video platform 30W exposure, small magic push helps physical businesses turn losses into profits
数据安全产业系列沙龙(三)| 数据安全产业标准体系建设主题沙龙
Which software is good for machine vision?
Seal Library - installation and introduction
john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
随机推荐
A week of short video platform 30W exposure, small magic push helps physical businesses turn losses into profits
图书管理系统(山东农业大学课程设计)
基于Impala的高性能数仓实践之执行引擎模块
深度学习图像数据自动标注[通俗易懂]
[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
Résumé de l'entrevue de Dachang Daquan
台积电全球员工薪酬中位数约46万,CEO约899万;苹果上调日本的 iPhone 售价 ;Vim 9.0 发布|极客头条...
According to the atlas of data security products and services issued by the China Academy of information technology, meichuang technology has achieved full coverage of four major sectors
Typescript array out of order output
Headline | Asian control technology products are selected in the textile and clothing industry digital transformation solution key promotion directory of Textile Federation
Data security industry series Salon (III) | data security industry standard system construction theme Salon
Aike AI frontier promotion (2.15)
Classifier visual interpretation stylex: Google, MIT, etc. have found the key attributes that affect image classification
Summary | three coordinate systems in machine vision and their relationships
Day 18 of leetcode dynamic planning introduction
Bib | graph representation based on heterogeneous information network learning to predict drug disease association
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...
PCL 点云镜像变换
Trigger: MySQL implements adding or deleting a piece of data in one table and adding another table at the same time
只是巧合?苹果iOS16的神秘技术竟然与中国企业5年前产品一致!