当我没有声明函数原型(prototype)并且只有一个函数时,它会运行。但是,当我有多个函数时,它会给我错误:
type mismatch in redeclaration of "function-name"
#include <conio.h>
#include <stdio.h>
float area1(float, float);
float area (float, float);
void main()
{
float x;
float y;
float a;
float z;
clrscr();
x = 5.0;
y = 5.0;
z = area(x, y);
a = area1(x, y);
printf("%f", z);
printf("%f", a);
getch();
}
void area(float a, float b)
{
int c;
c = 0.5 * a * b;
return c;
}
void area1(float a, float b)
{
int c;
c = 0.5 * a * b;
return c;
}
您通常希望在使用前对函数进行原型(prototype)设计。功能的数量无关紧要,但顺序很重要。有两种典型的做事方式:
- 基本上以相反的顺序编写函数,文件开头是最低级别的函数,然后是更高级别的函数(使用较低级别的函数)。
- 在函数实现之前使用单独的原型(prototype)(通常在标题中)。
我是一名优秀的程序员,十分优秀!