...
C++ is a high-performance, compiled, object-oriented programming language created by Bjarne Stroustrup. It is widely used for system software, game engines, embedded systems, and competitive programming.
✅ Supports both procedural and object-oriented programming
✅ Provides fine control over memory with pointers
✅ Used in operating systems, browsers, finance, robotics, and more
A variable stores data in memory. You must declare the type before using it.
Example:
int age = 21;
string name = "Maya";
To use strings in C++, include the string header:
#include <string>
int – Whole numbers
float / double – Decimal values
char – A single character
bool – True or False
string – A sequence of characters (text)
Output (printing to screen):
cout << "Hello Ardiland!";
Input (user typing a value):
int age;
cin >> age;
To use cin and cout, include:
#include <iostream>
using namespace std;
Used to run code based on a condition.
if (age >= 18) {
cout << "You are an adult.";
} else {
cout << "You are a minor.";
}
For Loop:
for (int i = 0; i < 5; i++) {
cout << i << " ";
}
While Loop:
int i = 0;
while (i < 5) {
cout << i << " ";
i++;
}
A function is a reusable block of code that performs a task.
void greet(string name) {
cout << "Hello " << name;
}
To call the function:
greet("Maya");
A class is a blueprint for objects. It groups variables (data) and methods (functions).
class Student {
public:
string name;
int age;
};
An object is an instance of a class.
Student s1;
s1.name = "Christian";
s1.age = 22;
Encapsulation – Keep data safe using access specifiers (private, public)
Inheritance – One class can inherit from another
Polymorphism – Same function behaves differently based on context
Abstraction – Hide implementation details and show only essentials
An array stores multiple items of the same type.
int scores[3] = {90, 85, 78};
cout << scores[0]; // Output: 90
To catch runtime errors:
try {
throw "Something went wrong!";
} catch (const char* msg) {
cout << msg;
}
Note: C++ uses exceptions less frequently than Java or Python. Often, programmers check manually for errors.
✅ Operating systems (Windows, macOS, Linux kernel modules)
✅ Game engines (Unreal Engine)
✅ Embedded systems (microcontrollers, IoT)
✅ Real-time systems (telecom, robotics, trading systems)
✅ Competitive programming (for speed and memory control)