Your technical depth starts here.
C++ Foundations and Compilation
1.1 Module Overview
This module introduces C++ as a multi-paradigm language that combines low-level control with high-level abstractions. You will write and compile your first program and learn the compiler flags that make you a safer programmer.
By the end of this module, you should be able to:
- Explain what C++ is and where it is used.
- Write, compile, and run a basic C++ program.
- Choose between
'\n'andstd::endl. - Compile with warning and sanitizer flags.
- Describe the learning path for the rest of the course.
1.2 What is C++?
C++ is a compiled, general-purpose language that supports several programming styles in one language:
- Procedural programming
- Object-oriented programming (OOP)
- Generic programming with templates
- Functional-style programming with lambdas and algorithms
- Systems and performance-sensitive programming
C++ is not "C with classes". It combines low-level control with high-level abstractions, and its most important modern idea is RAII: tying resource cleanup to object lifetime.
Where C++ is used
- DSA and competitive programming
- Game engines and computer graphics
- Operating systems, browsers, and databases
- Trading systems and high-performance backends
- Embedded systems, robotics, and simulation
1.3 Your First C++ Program
#include <iostream>
int main() {
std::cout << "Hello, CodeStudio!\n";
return 0;
}Line-by-line
#include <iostream>brings in the input/output stream library.int main()is the entry point. Unlike C,main()with empty parentheses means "no parameters".std::coutwrites to the console.<<is the stream insertion operator.return 0;signals success (optional inmain, but good to show).
'\n' versus std::endl
std::cout << "Hello\n"; // newline only (preferred)
std::cout << "Hello" << std::endl; // newline AND flushstd::endl flushes the output buffer every time, which is slower. Prefer '\n' unless you truly need a flush.
1.4 Compiling a C++ Program
g++ -std=c++20 -Wall -Wextra -Wpedantic main.cpp -o main
./mainUseful flags
-std=c++20uses C++20 language features.-Wallenables common warnings.-Wextraenables additional warnings.-Wpedanticwarns about non-standard constructs.-gadds debugging information.-O2enables optimization.
Recommended while learning
g++ -std=c++20 -Wall -Wextra -Wpedantic -g main.cpp -o mainCatching memory bugs during development
g++ -std=c++20 -Wall -Wextra -g \
-fsanitize=address,undefined main.cpp -o mainAddressSanitizer and UndefinedBehaviorSanitizer catch many memory errors and undefined behavior at runtime. They are testing tools, not a replacement for correct design.
1.5 Learning Map
C++ Fundamentals
↓
Functions, References and Memory
↓
Classes and Objects
↓
Constructors and Destructors
↓
Encapsulation and Static Members
↓
Inheritance
↓
Polymorphism and Virtual Functions
↓
Abstraction and Interfaces
↓
Copying, Moving and Resource Ownership
↓
STL Containers, Iterators and Algorithms
↓
Templates and Generic Programming
↓
Exception Handling
↓
Modern C++ Features
↓
Concurrency Basics
↓
Common Bugs and Interview Practice1.6 What You Will Be Able to Do
After this course you should be able to:
- Explain the compilation process and program structure.
- Use classes, constructors, destructors, and encapsulation correctly.
- Explain inheritance, polymorphism, virtual functions, and abstract classes.
- Use pointers, references, and smart pointers appropriately.
- Explain shallow copy, deep copy, and move semantics.
- Apply the Rule of Three, Five, and Zero.
- Use STL containers, iterators, and algorithms.
- Write templates, lambdas, and exception-safe code.
- Avoid object slicing, leaks, dangling references, and undefined behavior.
1.7 Practice Exercises
- Compile Hello World with
-Wall -Wextra -Wpedanticand read every warning. - Replace
'\n'withstd::endland explain the difference. - Compile any program with
-fsanitize=address,undefined. - Write your name and age on two lines using
std::cout.
1.8 Module Recap
In this module, you learned:
- C++ is multi-paradigm and gives low-level control with high-level abstractions.
- Compile with warnings turned on and treat them as potential bugs.
- Prefer
'\n'overstd::endl. - Use sanitizers during development.
