Functions and Files - Terminology Reference
This lesson provides a comprehensive reference of all the key C++ terminology you'll encounter throughout the chapter. Think of it as your programming vocabulary guide for functions, files, and program organization - these are the essential terms every C++ programmer needs to know when building larger programs.
How to Use This Reference
Don't memorize everything now! This lesson is designed to be a reference you come back to as needed:
- First time through: Read quickly to get familiar with the terms
- During other lessons: Return here when you encounter unfamiliar terminology
- When stuck: Use this as a quick lookup guide
- Before quizzes: Review relevant sections to refresh your memory
Functions Fundamentals
| Term |
Definition |
Example |
| Function |
A named group of statements that perform a specific task and can be called from other code |
See below |
| Function call |
The act of executing a function by using its name followed by parentheses |
add(5, 3) |
| Function body |
The statements enclosed in curly braces that make up the function's implementation |
{ return width * width; } |
| Return type |
Specifies what type of value (if any) the function gives back to the caller |
int, double, void |
| Return value |
The actual value that a function sends back to the code that called it |
42 in return 42; |
| Return statement |
Statement that exits a function and optionally sends a value back |
return result; |
| Void function |
A function that performs actions but doesn't return a value |
void printMessage() |
| Value-returning |
A function that performs calculations and returns a result |
See below |
Function Example
int add(int a, int b) {
return a + b;
}
Function Parameters & Arguments
| Term |
Definition |
Example |
| Parameter |
A variable declared in a function header that receives values from the caller |
int x in void func(int x) |
| Argument |
The actual value passed to a function when it's called |
5 in func(5) |
| Parameter list |
All parameters in a function header, separated by commas |
(int a, int b, double c) |
| Argument list |
All arguments in a function call, separated by commas |
func(10, 20, 3.14) |
| Pass by value |
Method where function receives copies of argument values |
func(x) func gets a copy of x |
| Local variable |
A variable declared inside a function, only accessible within that function |
int sum in { int sum = a + b; } |
Scope & Lifetime
| Term |
Definition |
Example |
| Scope |
The region of code where a variable can be accessed |
Inside vs outside functions |
| Local scope |
The area inside a function where local variables can be accessed |
Within function braces { } |
| Global scope |
The area outside all functions where global variables can be accessed |
Outside any function |
| Variable lifetime |
How long a variable exists in memory during program execution |
Function call duration |
| Out of scope |
When a variable cannot be accessed because it's outside its defined region |
Using local var outside of functions |
| Shadowing |
When a local variable has the same name as a global variable, hiding the global |
Local x hiding global x |
Understanding Scope
Scope determines where in your program a variable can be accessed. Think of scope as the "visibility zone" for your variables - some variables are visible everywhere, while others are only visible in specific areas of your code.
Variable Shadowing occurs when you create a local variable with the same name as a global variable. The local variable "shadows" (hides) the global one within that scope. It's like having two people named "John" in different rooms - when you're in the local room, "John" refers to the person in that room, not the one outside.
Four Main Scope Areas with Shadowing example
#include <iostream>
// 1. GLOBAL SCOPE - Variables here are visible everywhere
int globalCounter = 0;
int number = 100;
// 2. FUNCTION SCOPE - Each function creates its own scope
void demonstrateScope() {
int localNumber = 42; // Local variable
int number = 50; // Shadows global variable
// 3. BLOCK SCOPE - Nested scope within function
{
int blockVariable = 10;
std::cout << "Block can access: " << localNumber << ", " << blockVariable << std::endl;
// blockVariable only exists in this block
}
// Variable Shadowing in action
std::cout << "Local number: " << number << std::endl; // Prints: 50 (local)
std::cout << "Global number: " << ::number << std::endl; // Prints: 100 (global)
// std::cout << blockVariable; // ❌ ERROR: Out of scope
}
int calculateSum(int a, int b) {
// 4. PARAMETER SCOPE - Parameters act like local variables
int result = a + b;
globalCounter++; // Can access globals
return result;
}
int main() {
std::cout << "Initial global: " << number << std::endl; // Prints: 100
demonstrateScope();
calculateSum(5, 3);
std::cout << "Global unchanged: " << number << std::endl; // Still prints: 100
return 0;
}
Function Organization
| Term |
Definition |
Example |
| Function definition |
Provides the actual implementation/body of the function |
See Function Example above |
| Function declaration |
Tells compiler about function's existence without providing implementation |
int add(int a, int b); |
| Function signature |
The function's name and parameter types (used to identify unique functions) |
add(int, int) (has no return type or name) |
| Forward declaration |
Declaring a function before defining it, allows calling before definition |
void process(int count); |
| Function prototype |
Another term for forward declaration, shows function interface |
See Function prototype above |
| Function overloading |
Having multiple functions with same name but different parameters (compiler uses function signatures) |
print(int) vs print(string) |
Files & Program Structure
| Term |
Definition |
Example |
| Source file |
A file containing C++ code implementation, typically with .cpp extension |
main.cpp, utils.cpp |
| Header file |
A file containing declarations and interfaces, typically with .h extension |
utils.h, constants.h |
| Interface |
The public-facing declarations that other code can use, usually in .h files |
Function prototypes |
| Implementation |
The actual code that performs the work, usually in .cpp files |
Function bodies |
| Translation unit |
A single source file along with all the headers it includes |
One .cpp + its includes |
| Compilation unit |
Another term for translation unit |
Same as translation unit |
Header Files & Include System
| Term |
Definition |
Example |
| #include directive |
Preprocessor command that inserts contents of another file |
#include "myheader.h" |
| System header |
Standard library headers provided by the compiler |
#include <iostream>, #include <string> |
| User-defined header |
Headers created by the programmer for their specific project |
"calculator.h" |
| Angle brackets |
Used for including system/standard library headers |
#include <iostream> |
| Double quotes |
Used for including user-defined headers |
#include "myfile.h" |
| Header guard |
Mechanism to prevent a header from being included multiple times |
#ifndef, #define, #endif |
| Include guard |
Another term for header guard |
Same as header guard |
| Multiple inclusion |
Problem when same header is included multiple times causing errors |
Solved by header guards |
Preprocessor Concepts
| Term |
Definition |
Example |
| Preprocessor |
Tool that processes code before compilation, handles #directives |
Handles all # commands |
| Preprocessor directive |
Commands starting with # that are processed before compilation |
#include, #define |
| Macro |
Text replacement performed by preprocessor |
#define PI 3.14159 |
| Conditional compilation |
Using preprocessor to include/exclude code based on conditions |
#ifdef DEBUG |
| #ifndef |
"If not defined" - used in header guards |
#ifndef MYHEADER_H |
| #define |
Defines a macro or symbol for preprocessor |
#define MYHEADER_H |
| #endif |
Ends a conditional preprocessor block |
Closes #ifndef block |
Namespaces
| Term |
Definition |
Example |
| Namespace |
A named scope that groups related functions, variables, and types |
std namespace |
| std namespace |
Standard namespace containing all standard library components |
std::cout, std::cin |
| Scope resolution |
Using :: operator to specify which namespace a name belongs to |
std::cout |
| Using declaration |
Brings specific names from a namespace into current scope |
using std::cout; |
| Using directive |
Brings all names from a namespace into current scope |
using namespace std; |
| Naming collision |
When two or more names conflict in the same scope |
Two functions named add |
| Global namespace |
The default namespace when no specific namespace is declared |
Outside any namespace usually in the global scope |
Effective Function Design Practices
| Term |
Definition |
Example |
| Single responsibility |
Each function should have one clear, well-defined purpose |
calculateTax() only calculates tax |
| Function naming |
Using descriptive names that clearly indicate function purpose |
calculateMonthlyPayment() |
| Parameter validation |
Checking that function inputs are valid before processing |
Checking for negative values |
| Function documentation |
Comments explaining what function does, its parameters and return |
Comments above function header |
| Pure function |
Function that always returns same output for same input, no side effects |
Mathematical calculations |
| Side effect |
When function modifies something outside its own scope |
Printing to console |
Common Development Process Terms
| Term |
Definition |
When Used |
| Top-down design |
Starting with main problem and breaking into smaller sub-problems |
Planning program structure |
| Bottom-up design |
Building small components first, then combining into larger system |
Building utility functions |
| Incremental development |
Adding one function at a time and testing before adding more |
Step-by-step programming |
| Code refactoring |
Improving code structure without changing its functionality |
After getting code working |
| Function testing |
Verifying that individual functions work correctly in isolation |
Before integration |
Error Handling & Debugging
| Term |
Definition |
Example |
| Function call stack |
The sequence of function calls currently active in program |
main() → func1() → func2() |
| Stack overflow |
Error when too many function calls exceed available memory |
Infinite recursion |
| Function signature mismatch |
When function call doesn't match declaration parameters |
Calling add(int) with add(int,int) |
Next Steps
Take the quiz to test your knowledge of these fundamental C++ terms. Don't worry if you need to refer back to this guide - that's what it's for!