两个步骤: 1.先定义函数: 格式
返回值类型 函数名 (参数列表){
函数具体的代码
}
(1) 参数是可选的(可有可无)
(2) void 这个函数没有返回值
2, 调用函数 在调用函数时,实参与形参必须满足3个条件:个数相等、顺序对应,类型匹配。 格式
返回值 = 函数名(参数)
#include
/*
函数:实现特定功能的代码段
我给它一些什么,它给我做什么事,还给我什么
*/
void printAge(){
int age = 18;
printf("--------------------\n");
printf("年龄是:%d\n",age);
printf("--------------------\n");
}
int main(){
printAge();
printAge();
printAge();
printAge();
printAge();
printAge();
return 0;
}
#include
void printMyAge(int age){
printf("--------------------\n");
printf("年龄是:%d\n",age);
printf("--------------------\n");
}
int main(){
printMyAge(20);//调用函数
printMyAge(28);//调用函数
printf("%d",18);
printf("%d",19);
return 0;
}