c - "implicit declaration of function"是什么意思?

标签 c

#include <stdio.h>

int main()
{
    int a = 4;
    int b = 3;
    addNumbers(a, b);
}

int addNumbers(int a, int b)
{
    return a + b;
}

为什么这不能编译,我收到一条消息说函数 addNumbers() 的隐式声明?

最佳答案

要么在 main() 之前定义函数,要么在 main() 之前提供其原型(prototype)。

所以要么这样做:

#include <stdio.h>

int addNumbers(int a, int b)
{ //definition
}

int main()
{ //Code in main
  addNumbers(a, b);
}

或者这个:

#include <stdio.h>

int addNumbers(int, int);
int main()
{ //Code in main
  addNumbers(a, b);
}

int addNumbers(int a, int b)
{ // definition
}

关于c - "implicit declaration of function"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2161304/

相关文章:

c - 在 C 中使用堆栈

c - 当结构体包含字符串时为其分配内存

c - 将字符复制到 char 指针数组时的堆栈转储

c - 使用链表函数的内存范围

C - 从格式化的文本文件中读取带有整数的字符串

c - (C Linux) 中的 read() 和缓冲区大小错误

c - 打印文件中字符串的所有 k 聚体

c++ - 无法在 eclipse cdt 中构建 makefile

c - 多个目录下的头文件 : Best Practices

c - 15幻灯片益智游戏: Segmentation fault (core dumped) error