C++学习第三十六篇

/*
* 函数的声明
* 作用:告诉编译器函数名称及如何调用函数。函数的实际主体可以单独定义
* 函数的声明可以多次,但是函数的定义只能有一次
*/
#include<iostream>
using namespace std;
int max1(int a, int b);//将函数放置main函数后面时,没有函数声明会报错!

int main()
{
	cout << max1(10, 20) << endl;
	system("pause");
	return 0;
}

int max1(int a, int b)
{
	return a > b ? a : b;
}

//以下是错误的,函数只能定义一次
//int max1(int a, int b)
//{
//	return a > b ? a : b;
//}			    

猜你喜欢

转载自blog.csdn.net/weixin_47358937/article/details/121534988