gpt4 book ai didi

c - 函数如何对程序中的其他函数可见?

转载 作者:行者123 更新时间:2023-11-30 18:21:29 25 4
gpt4 key购买 nike

#include<stdio.h>
int main(void)
{
int a=3,b=4;
int c;
c = max_min(a,b);
printf("the max no is %d\n",c);
}
int max_min(int a,int b)
{
if(a>b)
return a;
else if(b>a)
return b;
}

Error: 'max_min' was not declared in this scope c = max_min(a,b);

请帮帮我

最佳答案

要么在 main 之前定义函数,要么给出函数的前向声明。像这样 -

#include<stdio.h>
int max_min(int a,int b); // forward declaration
int main(void){
// your code

}
// rest of code

在使用函数之前,您需要定义或提供前向声明,否则编译器将抛出错误,因为在此之前它看不到函数定义或声明。

关于c - 函数如何对程序中的其他函数可见?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43556938/

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