gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 16:28:20 26 4
gpt4 key购买 nike

#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/

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