Purpose: Header files contain declarations of functions, classes, variables, and other constructs. They act as an interface that other files can include and use.
Usage: Header files are typically included in source files (.cpp), allowing those source files to access the declarations inside the headers.
// mathutils.h
#ifndef MATHUTILS_H
#define MATHUTILS_H
// Function declaration
int add(int a, int b);
int multiply(int a, int b);
#endif
Purpose: Source files contain the actual implementation (definitions) of functions, classes, and other constructs declared in header files.
Usage: The .cpp file includes the header file and provides the definitions for the functions declared in the header.
// mathutils.cpp
#include "mathutils.h"
// Function definitions
int add(int a, int b) {
return a + b;
}
int multiply(int a, int b) {
return a * b;
}
Libraries are collections of precompiled code that you can reuse in your programs. There are two main types of libraries: