How do I use extern to share variables between source files?
@lebyy▲ 0 net votes
Problem: I know that global variables in C sometimes have the extern keyword. What is an extern variable? What is the declaration like? What is its scope? This is related to sharing variables across source files, but how does that work precisely? Where do I use… Fix (from the top answer): Using extern is only of relevance when the program you're building consists of multiple source files linked together, where some of the variables defined, for example, in source file file1.c need to be referenced in other source files, such as file2.c . It is important to understand the difference between defining a…