Introduction to C++ Programming

C++ was developed by Bjarne Stroustrup at AT&T Bell Labs in 1979. Though it is an object-oriented programming language; but still supports procedural and generic programming.

C++ is an extension to C programming (initially known as “C with Classes”).

C++ is a superset of C, and that practically any legal C program is a legal C++ program.

C++ is considered as a middle-level language, as it includes a combination of both high-level and low-level language features.

C++ is a powerful general-purpose language and widely used for developing operating systems, web browsers, video games, embedded systems, and so on.

C++ is compiled and case-sensitive language that runs on various platforms such as UNIX, Linux, MS Windows, and Mac.


C++ Environment

As expected, before writing a program and running it, we need to understand the C++ Environment first. Here, all the programs in this website are compiled and run using the Dev-C++ IDE on MS Windows platform. This IDE basically uses MinGW64 (64-bit) GNU C++ compiler for its operation.


First C++ Program

Let us develop our first C++ program.

Open Dev-C++ IDE and go to File > New > Source File.

Write the following C++ program and save the program file as hello.cpp (File > Save File as):

Note: A C++ program file is normally having the .cpp extension.


Hello from TechGuru


Explanation of the program

Line 1: The header #include <iostream>  is a “preprocessor” directive that tells the compiler to put code from the library header file called iostream into our program. Basically, it helps us to work with input and output objects, such as cin and cout.

Line 2: The header using namespace std tells the compiler to use names for objects and variables from the standard library (std). This allows the program to use objects such as cout (which is an object of the ostream class).

Line 3: It denotes a blank line. As usual, C++ ignores white space.

Line 4: The function that always appears in a C++ program is the int main(). Code written inside its curly brackets { } will be executed.

Line 5: Here, cout is an object used together with the insertion operator (<<) to output/print text. In our example it will output “Hello from TechGuru!”.

Line 6: The statement return 0 is the last statement inside the main() function.

Line 7: The closing curly bracket ‘}‘ indicates the end of the main() function.