Welcome to C++: Performance and Control

C++ was created by Bjarne Stroustrup in the early 1980s as an extension of the C language, adding object-oriented features while keeping C’s close-to-the-hardware performance. It compiles directly to native machine code and gives you fine-grained control over memory — this combination of speed and control is why C++ powers game engines (Unreal Engine is […]

Variables, Data Types and the Compiler

Like Java, C++ is statically typed — every variable’s type is fixed at compile time and checked by the compiler before your program ever runs. int age = 25;ndouble price = 19.99;nchar grade = ‘A’;nbool isActive = true;nstd::string name = “Tutoline”; Common types int — a whole number, typically 32 bits double — a decimal […]

Operators and Control Flow

Conditionals int score = 82;nstd::string grade;nif (score >= 90) {n grade = “A”;n} else if (score >= 75) {n grade = “B”;n} else {n grade = “C”;n} Loops for (int i = 0; i < 5; i++) {n std::cout << “Lesson ” << i << std::endl;n}nnint attempts = 0;nwhile (attempts < 3) {n attempts++;n} Reading […]

Functions and Pointers

int add(int a, int b) {n return a + b;n}nnint total = add(2, 3); // 5 Pass by value vs pass by reference void double_it(int value) {n value = value * 2; // only changes the local copyn}nnvoid double_it_ref(int &value) {n value = value * 2; // changes the caller’s actual variablen}nnint score = 10;ndouble_it(score);nstd::cout […]

Arrays, Vectors and Strings

Fixed-size arrays int scores[3] = {90, 85, 78};nstd::cout << scores[0]; // 90nstd::cout << sizeof(scores) / sizeof(scores[0]); // 3 — there’s no built-in .length A raw C++ array has no built-in way to ask its own length — you either track the size separately or use the somewhat awkward sizeof trick above. This is exactly the […]

Object-Oriented Programming: Classes and Objects

class Course {npublic:n Course(std::string title, int lessonCount) {n this->title = title;n this->lessonCount = lessonCount;n }nn std::string getTitle() {n return title;n }nnprivate:n std::string title;n int lessonCount;n};nnCourse cppCourse(“C++”, 10);nstd::cout << cppCourse.getTitle(); // C++ public vs private Members listed under private can only be accessed from inside the class itself — outside code must go through public methods […]

Memory Management and What’s Next

Stack vs heap Ordinary variables live on the stack and are cleaned up automatically the moment they go out of scope — no extra code required. Memory you allocate manually with new lives on the heap instead, and stays reserved until you explicitly free it yourself with delete. int* score = new int(90); // allocated […]

Templates and Generic Programming

A template lets you write one function or class that works with any type, without writing a separate version for each — the C++ equivalent of Java’s generics, and a feature that predates Java’s by several years. template<typename T>nT max_of(T a, T b) {n return (a > b) ? a : b;n}nnstd::cout << max_of(3, 7); […]

The Standard Template Library (STL) in Depth

Common containers #include <map>n#include <set>nnstd::map<std::string, int> scores;nscores[“Yash”] = 95;nscores[“Ana”] = 88;nnstd::set<std::string> uniqueCourses;nuniqueCourses.insert(“C++”);nuniqueCourses.insert(“C++”); // ignored — sets don’t allow duplicatesnstd::cout << uniqueCourses.size(); // 1 std::map keeps its keys sorted automatically (an unordered_map variant trades that ordering for typically faster average lookups). Both give you the same key-value lookup idea you’ve already seen in Python’s dictionaries and […]