the world: C++. This chapter will provide you with an overview of the C++ programming
language and its features.
"C++ is a high-performance, statically typed, and compiled programming language that supports
procedural, object-oriented, and generic programming" (Bjarne Stroustrup, the creator of C++).
C++ is an extension of the C programming language, and it was designed to add object-oriented
features to its predecessor while retaining its efficiency and flexibility.
Let's start with an anecdote: Did you know that C++ was initially called "C with Classes"
because it was designed as an extension of C with object-oriented features? The name was
later changed to C++ to reflect its capability to handle "objects-plus-plus."
One of the critical features of C++ is its support for various programming paradigms. These
paradigms include:
Procedural Programming: C++ supports procedural programming, where the program is
organized around procedures or functions that perform specific tasks.
Example: Here is a simple C++ program that calculates the factorial of a number using a
procedural approach:
#include <iostream>
using namespace std;
int factorial(int n); // Function declaration
int main() {
int num;
cout << "Enter a positive integer: ";
cin >> num;
cout << "Factorial of " << num << " = " << factorial(num);
return 0;
}
int factorial(int n) { // Function definition
if (n == 1)
return 1;
else
return n * factorial(n - 1);
}
Object-Oriented Programming (OOP): C++ supports fundamental concepts of OOP such as
classes, objects, inheritance, polymorphism, and encapsulation.