【问题标题】:In this question, which one is known as function declaration (prototype)? [duplicate]在这个问题中,哪一个被称为函数声明(原型)? [复制]
【发布时间】:2021-02-19 18:05:40
【问题描述】:
void add (int a, int b)
{
  int c= a+b;
  printf("the value of c is %d",c);
}

void main()
{    
  int x,y;
  printf("Enter two numbers: ");
  scanf("%d %d",&x,&y);
  add (x,y);
}

我了解什么是减速功能或原型...但是哪个 这个程序中的代码行被认为是一个函数原型 .....或者这个程序中没有任何函数原型???

【问题讨论】:

  • 谢谢@tadman,但我明白函数定义和原型之间的区别......我的问题是这个程序中的哪一行被认为是函数声明或原型?
  • 您发布的代码中没有原型或声明,只有定义。
  • 看,不要把我全都这样。它在大喊大叫,这很荒谬。
  • 定义算作声明,反之则不行。
  • @tadman haha​​ 对不起帽子人

标签: c function prototype


【解决方案1】:

在您的代码中,您根本没有编写函数声明。

顺便说一下void main()不正确,请始终使用int main()

// function declaration
void add (int a, int b);

// function definition
void add (int a, int b)
{
   int c= a+b;
   printf("the value of c is %d",c);
}

void main()
{

    int x,y;
    printf("Enter two numbers: ");
    scanf("%d %d",&x,&y);
    // function call
    add (x,y);
}

【讨论】:

  • 我不认为有必要在 C 中写好函数的定义之后在顶部写函数原型...
  • 这不是必需的,但这是您为问题命名的方式,因此添加它似乎完全有效,即使在这种情况下不需要它,因为您询问过它。你可能会放松一下帽子,它没有帮助。
  • 函数定义也是声明。
猜你喜欢
  • 2014-04-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-09
  • 2011-02-04
  • 1970-01-01
  • 1970-01-01
  • 2012-08-21
相关资源
最近更新 更多