C语言_函数_基本[4]

  • 函数定义
return_type function_name(parameter list){
	body of the function
}

返回类型:
	有返回值时就是返回值的数据类型(:int double);没有返回值时为void类型(空类型)
函数名: 要符合命名规范。
参数列表[可选]:	包括函数参数的类型、顺序、数量。
				这儿的参数是形参,也就是占位符。	
//实参是函数被调用时实际传入的具体的一个值。
  • 函数声明
    在函数声明中,参数的名称并不重要,只有参数的类型是必需的,因此下面也是有效的声明
int max(int,int);
#include<stdio.h>
int max(int n1,int n2);  //函数声明
int main(){
        int num1 = 100;
        int num2 = 200;
        int result2;
        result2 = max(num1,num2); //函数调用
        printf("max is : %d\n",result2);

        return 0;
}
//函数定义
int max(int n1,int n2){
        int result;
        if(n1 > n2){
                result = n1;
        }else{
                result = n2;
        }
        return result;
}
发布了80 篇原创文章 · 获赞 0 · 访问量 1751

猜你喜欢

转载自blog.csdn.net/weixin_41272269/article/details/104148743
今日推荐