Table of Contents
What is C++?
C++ is a powerful general-purpose programming language. It can be used to develop operating systems, browsers, games, and so on. C++ supports object-oriented, procedural, and generic programming. This makes C++ powerful as well as flexible.
C++ is a middle-level language, as it encapsulates both high and low level language features.
C++ History
- C++ programming language was developed in 1980 by Bjarne Stroustrup at bell laboratories of AT&T (American Telephone & Telegraph), located in U.S.A.
- Bjarne Stroustrup is known as the founder of C++ language.
- It was develop for adding a feature of OOP (Object Oriented Programming) in C without significantly changing the C component.
- C++ programming is “relative” (called a superset) of C, it means any valid C program is also a valid C++ program.
Object-Oriented Programming (OOPs)
C++ supports object-oriented programming, the four major pillar of object-oriented programming (OPPs) used in C++ are:
- Inheritance
- Polymorphism
- Encapsulation
- Abstraction
C++ Standard Libraries
Standard C++ programming is divided into three important parts:
- The core library includes the data types, variables and literals, etc.
- The standard library includes the set of functions manipulating strings, files, etc.
- The Standard Template Library (STL) includes the set of methods manipulating a data structure.
Application of C++
By the help of C++ programming language, we can develop different types of secured and robust applications:
- Window application
- Client-Server application
- Device drivers
- Embedded firmware etc
C++ Hello World Program
Let’s have look on a simple C++ program to Print “Welcome to C++” message to the console.
#include <iostream>
using namespace std;
int main() {
cout << "Welcome to C++";
return 0;
}
Let’s go through it line by line:
#include <iostream>
: This line tells the compiler to include a header file called<iostream>
. This file contains definitions for input and output operations in C++, which we’ll use to print the message.using namespace std;
: This line tells the compiler to use thestd
namespace, which contains common C++ objects likecout
(used for output) andcin
(used for input). It’s a convenience so we don’t have to writestd::cout
every time.int main() {
: This line defines themain
function, which is the entry point of the program. When you run the program, this function is the first one that gets executed. Theint
part indicates that the function will return an integer value (in this case, 0 to signal successful execution).cout << "Welcome to C++";
: This line uses thecout
object from thestd
namespace to print the message “Welcome to C++” to the console (usually the command prompt or terminal window where you run the program). The<<
operator is the insertion operator, which is used to send data tocout
.return 0;
: This line returns the value 0 from themain
function, indicating that the program has executed successfully.