Function Prototypes and Scope
Learn about function declarations, local and global variables, and the scope of variables in C.
Function Prototypes and Scope is a free C Academy lesson on CoddyKit — lesson 2 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Function Prototypes and Scope
Function prototypes help declare functions before they are used.
Variable scope determines where a variable can be accessed.
In this lesson, you will learn:
- How to use function prototypes.
- The difference between local and global variables.
- How variable scope affects program behavior.

2
What is a Function Prototype?
A function prototype is a declaration of a function before it is defined.
Syntax:
returnType functionName(parameterType1, parameterType2);
Example:
int add(int, int);3
Example: Function Prototype
This program demonstrates the use of a function prototype.
#include <stdio.h>
int add(int, int); // Function prototype
int main() {
int sum = add(5, 10);
printf("Sum: %d\n", sum);
return 0;
}
int add(int a, int b) {
return a + b;
}4
Local vs Global Variables
Variables in C have different scopes:
- Local variables: Declared inside a function, accessible only within that function.
- Global variables: Declared outside functions, accessible throughout the program.
5
Example: Local Variable
This program demonstrates how a local variable is limited to a function.
#include <stdio.h>
void testFunction() {
int x = 10; // Local variable
printf("Inside function: %d\n", x);
}
int main() {
testFunction();
// printf("Outside function: %d\n", x); // Error: x is not accessible here
return 0;
}6
Example: Global Variable
This program demonstrates how a global variable is accessible across functions.
#include <stdio.h>
int globalVar = 100; // Global variable
void printGlobal() {
printf("Global variable: %d\n", globalVar);
}
int main() {
printGlobal();
return 0;
}7
Scope Rules in C
Scope defines where a variable can be accessed.
- Local variables exist only inside their function.
- Global variables exist for the entire program.
- Block scope variables exist within loops or conditional blocks.
8
9
Best Practices
To write clean and efficient code:
- Use global variables sparingly to avoid unintended modifications.
- Prefer function parameters over global variables for better control.
- Always declare function prototypes before use.
10
Summary
In this lesson, you learned:
- How function prototypes help declare functions before use.
- The difference between local and global variables.
- The scope of variables in C.
Next, we will explore recursion in C!

Frequently asked questions
Is the “Function Prototypes and Scope” lesson free?
Yes — the full text of “Function Prototypes and Scope” is free to read here on the web, and the C Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C Academy course, upgrade to CoddyKit PRO.
What will I learn in “Function Prototypes and Scope”?
Learn about function declarations, local and global variables, and the scope of variables in C. You practise C Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C Academy?
No prior experience is required. C Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Function Prototypes and Scope” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C Academy lesson?
Yes. Every C Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Defining and Calling Functions
- Function Prototypes and Scope
- Recursion in C