1.函数
1)函数声明:
一般在头文件.h里,对编译器说:这里我有一个函数叫function() 让编译器知道这个函数的存在。Ctrl+F12 跳到函数声明
函数声明告诉编译器函数的名称、返回类型和参数。
2)函数定义----函数具体实现
函数定义一般在源文件.cpp里,具体就是函数的实现过程,写明函数体。 F12 跳到函数定义,也就是函数具体实现
函数定义提供了函数的实际主体。
返回类型 函数名称( 参数 )
{
函数体
}
3)函数引用(调用):

#include <stdio.h>
include <stdlib.h>
void fun(int a, int b); /声明函数原型/
int main()
{
int a, b;
scanf("%d %d", &a, &b);
fun(a, b); /函数调用/
return 0;
}
void fun(int a, int b){ /函数定义/
int res = a + b;
printf("res = %d", res);
}
网友评论