小编Adi*_*aya的帖子

我们可以在C中的main函数中定义函数原型吗?

在我的大学,我们的老师教我们"我们在主要功能之前定义功能原型.喜欢:

#include<stdio.h>
void findmax(float, float);
int main()
{
    //code goes here
}
Run Code Online (Sandbox Code Playgroud)

但今天我的朋友告诉我他们学会了将原型放在主要功能中.喜欢:

#include<stdio.h>
int main()
{
    void findmax(float, float);

    float firstnum, secondnum;

    printf("Enter first:");
    scanf("%f", &firstnum);

    printf("Enter second:");
    scanf("%f", &secondnum);

    findmax(firstnum, secondnum);
}

void findmax(float x, float y)
{
    float maxnum;

    if(x>y)
    {
            maxnum=x;
    }

    else
    {
       maxnum=y;
    }

    printf("The max is %f", maxnum);
}
Run Code Online (Sandbox Code Playgroud)

它们都有效.我想知道它们之间是否存在差异.谢谢.

c prototype

4
推荐指数
1
解决办法
600
查看次数

标签 统计

c ×1

prototype ×1