首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

这代码在哪声明了自定义函数?解决方法

2012-06-19 
这代码在哪声明了自定义函数?C/C++ code#include stdio.hint main(){int a,b,sprintf(please input a:

这代码在哪声明了自定义函数?

C/C++ code
#include <stdio.h>int main(){   int a,b,s;   printf("please input a:\n");   scanf("%d",&a);   printf("please input b:\n");   scanf("%d",&b);   s=max(a,b);   printf("the max number is %d\n",s);   getch();}int max(int x ,int y)                /*定义一个函数。*/{   if(x>y)                        /*如果x大于y就返回x。*/   {      return(x);   }   else                        /*否则就返回y。*/   {      return(y);   }}


上面不是没有声明自定义函数吗?若有,哪行是?
编译运行却正常通过。


[解决办法]
1. C里面若没有看到函数声明,就使用的情况,就会根据参数的类型,自行构造一个与参数类型相同,假定返回int的函数声明。然后你下面实现了一个此原型的函数,编译成功。

2. C++编译错误

3. 若你的max函数的返回类型不是int,就会出错
[解决办法]
C/C++ code
test.c(10) : warning C4013: “max”未定义;假设外部返回 int //看这行test.c(12) : warning C4013: “getch”未定义;假设外部返回 intMicrosoft (R) Incremental Linker Version 10.00.40219.01Copyright (C) Microsoft Corporation.  All rights reserved. 

热点排行