0
0
Cprogramming~30 mins

Extern storage class - Mini Project: Build & Apply

Choose your learning style9 modes available
Using the extern Storage Class in C
📖 Scenario: You are working on a simple C program split into two files. One file holds a variable, and the other file uses that variable. To share the variable between files, you use the extern storage class.
🎯 Goal: Build a program with two files where one file declares a variable and the other file accesses it using extern. You will see how extern helps share variables across files.
📋 What You'll Learn
Create a global variable count in one file
Declare extern int count; in the other file
Modify count in the second file
Print the updated count value in the second file
💡 Why This Matters
🌍 Real World
Sharing variables across multiple files is common in large C programs to organize code and data.
💼 Career
Understanding <code>extern</code> is essential for working on multi-file C projects, embedded systems, and system programming.
Progress0 / 4 steps
1
Create a global variable in file1.c
In file1.c, create a global integer variable called count and set it to 10.
C
Need a hint?

Global variables are declared outside any function.

2
Declare extern variable in file2.c
In file2.c, declare the variable count using extern int count; to tell the compiler it is defined elsewhere.
C
Need a hint?

The extern keyword tells the compiler the variable is defined in another file.

3
Modify count in file2.c
In file2.c, write a function called increment that adds 5 to count.
C
Need a hint?

Functions can change the value of global variables.

4
Print the updated count in file2.c
In file2.c, write a main function that calls increment() and then prints the value of count using printf.
C
Need a hint?

Remember to include stdio.h to use printf.