Recall & Review
beginner
What is the purpose of the <code>extern</code> storage class in C?The <code>extern</code> storage class tells the compiler that a variable or function is defined in another file or location. It allows sharing variables or functions across multiple files.Click to reveal answer
beginner
How does
extern differ from static in C?extern makes a variable or function visible across multiple files, while static limits visibility to the current file only.Click to reveal answer
intermediate
What happens if you declare a variable with
extern but do not define it anywhere?The linker will give an error because it cannot find the actual definition of the variable.
extern only declares, it does not allocate memory.Click to reveal answer
beginner
Example: How to declare and use an
extern variable across two files?File1.c: <br>
int count = 10; <br> File2.c: <br> extern int count; // refers to count in File1.c <br> This allows File2.c to access the variable count defined in File1.c.Click to reveal answer
beginner
Can
extern be used with functions? If yes, how?Yes. Functions have external linkage by default. You can explicitly declare a function with
extern to indicate it is defined elsewhere, allowing calls across files.Click to reveal answer
What does the
extern keyword do in C?✗ Incorrect
extern declares a variable that is defined elsewhere, allowing cross-file access.If you use
extern int x; but never define x, what happens?✗ Incorrect
The linker cannot find the definition of
x, causing a linker error.Which storage class limits a variable's visibility to the current file?
✗ Incorrect
static limits visibility to the current file, unlike extern.Are functions extern by default in C?
✗ Incorrect
Functions have external linkage by default, so they are extern unless declared static.
How do you share a variable between two files in C?
✗ Incorrect
Define the variable in one file and declare it with
extern in the other to share it.Explain how the
extern storage class helps in sharing variables across multiple files in C.Think about how you tell the compiler a variable exists somewhere else.
You got /4 concepts.
Describe the difference between
extern and static storage classes in terms of variable visibility.Consider where the variable can be accessed from.
You got /4 concepts.