gpt4 book ai didi

c - 是否有必要在 C 中声明原型(prototype)?

转载 作者:太空宇宙 更新时间:2023-11-04 05:20:52 25 4
gpt4 key购买 nike

当我没有声明函数原型(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)设计。功能的数量无关紧要,但顺序很重要。有两种典型的做事方式:

  1. 基本上以相反的顺序编写函数,文件开头是最低级别的函数,然后是更高级别的函数(使用较低级别的函数)。
  2. 在函数实现之前使用单独的原型(prototype)(通常在标题中)。

关于c - 是否有必要在 C 中声明原型(prototype)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8997858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com