Fundamentals
Compiler vs Interpreter
Compiler | Interpreter |
|---|---|
Translates the entire source code into machine code at once, producing a separate executable file (e.g., | Translates and executes the source code line by line without generating a separate executable file. |
Compilation happens only once. After that, the program can run without the compiler. | Translation happens every time the program is run, so an interpreter is required each time. |
Compiled programs generally execute faster because they run directly on the machine. | Interpreted programs are usually slower because execution happens within the interpreter. |
Programming Paradigms
Monolithic Programming
The entire program is written as a single, large block of code, often in one file, with little or no separation of concerns.
Procedural / Modular / Functional Programming
The program is divided into smaller, reusable functions or modules that perform specific tasks.
Example: C language primarily follows the procedural programming paradigm.
Object-Oriented Programming (OOP)
The program is organized around objects and classes that encapsulate data and behavior.
Example: C++ supports object-oriented programming.
Header File
Contains declarations of functions, classes, macros, and constants.
Does not contain executable code (usually).
Used by the compiler during compilation.
They're included using
#include
iostream tells the compiler: “Relax, cout exists. I’ll show you the body later.”
Library File
Contains the definitions / implementations of functions and classes.
Provides the actual compiled code.
Used during linking.
Can be:
Static library (
.a,.lib)Dynamic library (
.so,.dll)
Example: libstdc++.so → contains the real implementation of cout.
Namespace
Problem:
Program will generate error, mentioning fun() is redefined.
Solution:
Namespace Summary
A namespace is a named scope that groups identifiers like variables, functions, and classes to avoid name collisions.