Introduction to C++
C++ is a general-purpose, high-performance programming language developed by Bjarne Stroustrup. The C++ language is an extension of the C programming language, designed to include object-oriented features along with low-level memory control.
The C++ language is known for its speed, efficiency, and flexibility. It allows developers to write programs that are both close to the hardware and highly structured. This unique combination makes the C++ language ideal for system software, real-time applications, and performance-critical programs.
Features of C++

The main features C++ programming language are as follows:
- Simple: It is a simple language in the sense that programs can be broken down into logical units and parts, and has a rich library support and a variety of datatypes.
- Machine Independent: C++ code can be run on any machine as long as a suitable compiler is provided.
- Low-level Access: C++ provides low-level access to system resources, which makes it a suitable choice for system programming and writing efficient code.
- Fast Execution Speed: C++ is one of the fastest high-level languages. There is no additional processing overhead in C++, it is blazing fast.
- Object-Oriented: One of the strongest points of the language which sets it apart from C. Object-Oriented support helps C++ to make maintainable and extensible programs. i.e. large-scale applications can be built.
History of C++
Understanding the history of C++ helps explain its lasting popularity. The C++ language was developed by Bjarne Stroustrup in the early 1980s as an extension of the C programming language. The goal was to add object-oriented features without sacrificing performance.
Over time, the C++ language evolved through multiple standards, including C++98, C++11, C++14, C++17, and C++20. Each version introduced powerful features that made the language safer, faster, and easier to use. Today, the C++ language continues to evolve, adapting to modern software development needs while maintaining backward compatibility.

Structure of the C++ program
Understanding the structure of a C++ program is the first step toward learning and mastering C++ programming. Every C++ program follows a logical and well-defined structure that helps the compiler understand how to execute the code. Knowing this structure makes your programs easier to read, write, and maintain.
A typical C++ program consists of the following main parts:
- Documentation Section
- Preprocessor Directives
- Global Declarations
main()Function- User-Defined Functions
Each of these components plays an important role in how a C++ program works.
Documentation Section
This section contains comments that describe the purpose of the program. Comments are ignored by the compiler but are very helpful for programmers.
// This program displays a welcome message
Comments improve code readability and make maintenance easier.
Preprocessor Directives
Preprocessor directives start with the # symbol and are processed before compilation begins. They are used to include header files and define macros.
#include <iostream>
using namespace std;
The #include directive allows access to predefined functions, while using namespace std; lets you use standard library features easily.
Global Declarations
Global declarations include variables, constants, and function prototypes that are declared outside any function. These can be accessed throughout the program.
int globalVariable;
This section helps in organizing shared data across multiple functions.
main() Function
The main() function is the heart of every C++ program. Execution of the program always starts from the main() function.
int main() {
cout << "Hello, World!";
return 0;
}
intspecifies the return type{ }define the function bodyreturn 0;indicates successful program execution
User-Defined Functions
User-defined functions are created to perform specific tasks. They help break large programs into smaller, manageable blocks.
void displayMessage() {
cout << "Welcome to C++ programming";
}
Functions improve reusability, readability, and modularity in C++ programs.
Complete Example of C++ Program Structure
// Program to display a message
#include <iostream>
using namespace std;
void displayMessage();
int main() {
displayMessage();
return 0;
}
void displayMessage() {
cout << "Welcome to C++ Programming";
}
Data types in C++
Data types define the kind of data a variable can store. In the C++ language, data types are categorized into three major groups: basic data types in C++, derived, and user defined data types. Understanding these categories is essential for writing efficient and error-free code.

Basic Data Types in C++
The basic data types in C++ are the foundation of any program written in the C++ language. These data types are used to store simple values and are built directly into the language.
Common basic data types in C++ include:
int– stores whole numbersfloat– stores decimal numbersdouble– stores large decimal values with higher precisionchar– stores single charactersbool– stores true or false values
Using the correct basic data types in C++ helps optimize memory usage and improves program performance, which is a major strength of the C++ language.
Derived Data Types in C++ Language
Derived data types are created from the basic data types in the C++ language. They allow programmers to store multiple values or represent complex data structures.
Examples of derived data types include:
- Arrays
- Pointers
- References
- Functions
These derived types enhance the flexibility of the C++ language and enable developers to write more structured and reusable code.
User Defined Data Types
User defined data types allow programmers to create their own custom data structures in the C++ language. This feature supports better organization and readability of large programs.
Common user defined data types include:
structunionenumclass
Classes, in particular, play a vital role in object-oriented programming, which is one of the most powerful features of the C++ language. By using user defined data types, developers can model real-world problems more effectively.
Role of Data Types in C++ Programming
Proper use of basic data types in C++, derived, and user defined data types ensures:
- Efficient memory management
- Better program structure
- Improved code readability
- Reduced runtime errors
This is why mastering data types is a critical step in learning the C++ language
Operators in C++
In simple terms, OPERATORS IN C++ are symbols that tell the compiler to perform specific operations. These operations may involve arithmetic calculations, logical decisions, data comparisons, or bit-level manipulations.
For example, the + operator is used to add two numbers, while the == operator is used to compare values. Every C++ program relies heavily on OPERATORS IN C++ to execute instructions correctly.
Types of Operators in C++
The OPERATORS IN C++ are broadly classified into several categories based on their functionality. Each type serves a unique purpose in programming.
Arithmetic Operators in C++
Arithmetic OPERATORS IN C++ are used to perform mathematical calculations.
Common arithmetic operators include:
+(Addition)-(Subtraction)*(Multiplication)/(Division)%(Modulus)
These OPERATORS IN C++ are frequently used in calculations, formulas, and algorithm development.
Example
#include <iostream>
using namespace std;
int main() {
int a = 10, b = 3;
cout << "Addition: " << a + b << endl;
cout << "Subtraction: " << a - b << endl;
cout << "Multiplication: " << a * b << endl;
cout << "Division: " << a / b << endl;
cout << "Modulus: " << a % b << endl;
return 0;
}
OUTPUT
Addition: 13
Subtraction: 7
Multiplication: 30
Division: 3
Modulus: 1
Relational Operators in C++
Relational OPERATORS IN C++ are used to compare two values and return a boolean result (true or false).
Examples include:
==(Equal to)!=(Not equal to)>(Greater than)<(Less than)>=(Greater than or equal to)<=(Less than or equal to)
These OPERATORS IN C++ are essential for decision-making statements such as if, else, and loops.
Example
#include <iostream>
using namespace std;
int main() {
int x = 5, y = 10;
cout << (x < y) << endl;
cout << (x > y) << endl;
cout << (x == y) << endl;
return 0;
}
OUTPUT
1
0
0
Logical Operators in C++
Logical OPERATORS IN C++ are used to combine multiple conditions.
The main logical operators are:
&&(Logical AND)||(Logical OR)!(Logical NOT)
Using logical OPERATORS IN C++, programmers can create complex conditions and control the flow of execution in a program.
Example
#include <iostream>
using namespace std;
int main() {
int a = 5, b = 10;
cout << (a < b && b > 5) << endl;
cout << (a > b || b > 5) << endl;
cout << !(a > b) << endl;
return 0;
}
OUTPUT
1
1
1
Assignment Operators in C++
Assignment OPERATORS IN C++ are used to assign values to variables.
Examples include:
=(Simple assignment)+=,-=,*=,/=(Compound assignment)
These OPERATORS IN C++ help reduce code length and improve readability.
Example
#include <iostream>
using namespace std;
int main() {
int x = 10;
x += 5;
cout << x << endl;
x -= 3;
cout << x << endl;
return 0;
}
OUTPUT
15
12
Increment and Decrement Operators
Increment (++) and decrement (--) OPERATORS IN C++ are used to increase or decrease a variable’s value by one.They are commonly used in loops and counters, making them an important part of efficient C++ programming.
Example
#include <iostream>
using namespace std;
int main() {
int a = 5;
cout << ++a << endl;
cout << a-- << endl;
cout << a << endl;
return 0;
}
OUTPUT
6
6
5
Bitwise Operators in C++
Bitwise OPERATORS IN C++ work directly on bits and are mainly used in low-level programming.
Common bitwise operators include:
&(AND)|(OR)^(XOR)<<(Left shift)>>(Right shift)
These OPERATORS IN C++ are especially useful in embedded systems and performance-critical applications.
Example
#include <iostream>
using namespace std;
int main() {
int a = 5, b = 3;
cout << (a & b) << endl;
cout << (a | b) << endl;
cout << (a ^ b) << endl;
return 0;
}
OUTPUT
1
7
6
