c - FuncA 未在此范围内声明 C 编程错误

标签 c

我只是 C 编程的新手,我正在努力学习这门语言。但是当我编译代码时,我让它显示错误 “FuncA was not declared in this scope”。但我已经尝试在下面声明函数。

 #include<stdio.h>

 int main(){     
   int A = 1;   
   FuncA(A);   
   printf("%d\n");     
 }

 int FuncA(int B){  
    B++;        
    return B++;
 }

抱歉这个问题。

最佳答案

你需要把它的声明:

int FuncA(int B);

main() 之前。

或者,您可以在函数定义之后移动 main()


P.S.:正如@JonathanLeffler 评论的那样,printf("%d\n")undefined behavior :

If any argument is not the type expected by the corresponding conversion specifier, or if there are less arguments than required by format, the behavior is undefined. If there are more arguments than required by format, the extraneous arguments are evaluated and ignored.

你可能想要这个:

printf("%d\n", FuncA(A));

关于c - FuncA 未在此范围内声明 C 编程错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23018561/

相关文章:

将英寸转换为厘米

c - C 结构中 malloc'd bool 值的默认值?

c++ - 为什么放置\n会改变执行顺序

c - 用 C 抓取网页最简单的方法是什么? (通过 https)

c - 为什么编译器不能插入代码来检测缓冲区溢出?

c - 使用循环将字符添加到 c 中的 "strings"数组时遇到问题?

c - 文件无法识别 : File format not recognized

c - 如何找出分配一个字符数组的空间大小

c++ - Borland C++ 不是 C++?

c - 返回数组中找到的所有偶数