头文件中的外部变量

头文件中的外部变量

本文介绍了头文件中的外部变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 目前正在了解外部变量。 我已声明一个名为的变量 int a = 10 int b = 10 在源文件文件中.c 在file1.c 我使用 extern int b; 并使用printf打印变量b。 当我使用 extern int a 。它显示错误,说它无法找到引用的变量。是否与编译器或ANSI C有关,当使用extern时,它不会在头文件中查找引用? 我必须使用#includehead.h打印变量a。 任何人都可以解释它的ANSI或visual studio是否有问题?解决方案 Currently learning about the extern variable .I have declared a variable calledint a=10 in a header file head.hint b=10 in a source file file.cIn file1.cI used extern int b;and printed the variable b using printf.when i use extern int a .It shows an error saying it cannot find the referenced variable . Is it something to do with compiler or ANSI C that does not look up for references in header when extern is used?I have to use #include "head.h" to print variable a.Can anyone explain whether its ANSI or visual studio problem? 解决方案 这篇关于头文件中的外部变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-22 17:30