C++ Language Overview
C++ is an object-oriented programming language developed by Bjarne Stroustrup in the
early 1980s as an extension of the C language. It combines the efficiency and low-level
control of C with features that support classes and objects. C++ is widely used for system
software, game development, GUI applications, embedded systems, and competitive
programming. It supports both procedural and object-oriented approaches, making it a
flexible and powerful language for both beginners and professionals.
Basic Structure and Syntax
A C++ program starts with header files, followed by functions and the main() function, where
execution begins. The iostream library is commonly used for input and output operations
through cin and cout.
Example:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, C++!" << endl;
return 0;
#include <iostream> imports input/output stream functions.
cout prints output, and cin takes input.
endl inserts a new line.
Every statement ends with a semicolon (;), and curly braces {} define blocks of code.
Data Types, Variables, and Operators
C++ supports data types like int, float, double, char, bool, and string. Variables must be
declared before use. Operators in C++ are similar to C, with some additional ones for OOP
and advanced programming.
Example:
int a = 10, b = 5;
float c = a / (float)b;
cout << "Result = " << c << endl;
Common operators include:
Arithmetic: +, -, *, /, %
Relational: ==, !=, >, <, >=, <=
Logical: &&, ||, !
Increment/Decrement: ++, --
Scope Resolution: :: (used to access global variables or functions)
Control Structures and Loops
C++ supports decision-making and looping statements that control the flow of execution.
Examples:
if(a > b)
cout << "A is greater";
else
cout << "B is greater";
for(int i = 1; i <= 5; i++)
cout << i << " ";
if-else: conditional branching
switch: multiple selection structure
for, while, do-while: loops used for iteration
Loop control statements like break, continue, and goto manage the flow of loops
effectively.
Object-Oriented Programming (OOP)
C++ introduced OOP concepts like classes, objects, inheritance, polymorphism,
encapsulation, and abstraction, which allow better organization of code and real-world
modeling.
Example:
class Student {
public:
string name;
int age;
void display() {
cout << "Name: " << name << ", Age: " << age << endl;
};
int main() {
Student s1;
[Link] = "Rahul";
[Link] = 20;
[Link]();
return 0;
Class: blueprint for objects.
Object: instance of a class.
Inheritance allows one class to derive features of another.
Polymorphism allows functions or operators to behave differently based on context.
Advanced Features and Memory Management
C++ supports pointers, references, and dynamic memory allocation using new and delete. It
also provides the Standard Template Library (STL), which contains built-in data structures
and algorithms such as vector, map, set, stack, and queue.
Example:
#include <vector>
int main() {
vector<int> nums = {1, 2, 3};
nums.push_back(4);
for(int n : nums)
cout << n << " ";
C++ is a compiled language that produces fast executables. Its strong typing, OOP support,
and low-level capabilities make it ideal for developing applications where both performance
and structure matter.