To declare a variable with file scope, we can declare it anywhere in a source file but outside of any function body. Consider the following code segment from nameSorter.c (Chapter 21, Exploring Formatted Input):
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
const int listMax = 100;
const int stringMax =80;
...
We have declared the listMax and stringMax variables as external variables outside of any function block. Instead of using those literal values in that program, we used listMax and stringMax whenever we needed those values. It has a scope that is visible throughout this file.
Now, suppose this program was part of a multi-file program. The other source files would not be able to use those variables; their scope is limited to just nameSorter.c. In the next section, we will see how to make these variables accessible to other files.