C语言编译error: too few arguments to function ‘imax‘

C语言编译error: too few arguments to function ‘imax’

C语言编译error: too few arguments to function ‘imax‘_第1张图片

错误代码(看看能找出是哪错了么?):
//proto.c--使用函数原型 
#include 
int imax(int, int);//旧式函数声明

int main(void)
{
	printf("The maximum of %d and %d is %d.\n", 3, 5, imax(3));
	printf("The maximum of %d and %d is %d.\n", 3, 5, imax(3.0, 5.0));
	
	return 0;
}

int imax(int n,int m)
{
	return(n>m?n:m);
}
修改后代码:
//proto.c--使用函数原型 
#include 
int imax(int, int);//旧式函数声明

int main(void)
{
	printf("The maximum of %d and %d is %d.\n", 
	3, 5, imax(3,5));	//imax(3)-->imax(3, 5)
	printf("The maximum of %d and %d is %d.\n", 3, 5, imax(3.0, 5.0));
	
	return 0;
}

int imax(int n,int m)
{
	return(n>m?n:m);
}

实参和形参在数量上、类型上、顺序上必须严格一致,否则会发生“类型不匹配”的错误。当然,如果能够进行自动类型转换,或者进行了强制类型转换,那么实参类型也可以不同于形参类型。

你可能感兴趣的:(c语言)