Introduction

C++ is one of the most popular programming languages. It is based on C but is an object-oriented programming language. It is widely used in graphics libraries, games, network devices, etc.

Why should we learn C++ ?

Features of C++

C++ is fast

Easy to learn

A powerful programming language

Has many built-in functions and operators which can make complex programs easy

Can be compiled on a number of computer platforms

C++ is an object-oriented programming language.

Use of pointer makes it a much more powerful language.

Also largely used in many large-scale projects

How to start ?

In this whole C++ tutorial, you will be learning about writing C++ programs. But what after that?

After writing any program, we need to compile and run it to see the output of the program.

So, what is meant by compiling ?

When we write our program in C++ language, it needs to be converted to machine language (which is binary language consisting of 0s and 1s) so that computer can understand and execute it. This conversion is known as compiling a program. We compile a code with the help of a compiler.

Integrated Development Environment (IDE)

To write and compile our C++ program, we have been provided with many IDEs.

An IDE consists of a Text Editor as well as a Compiler. We type our program in the text editor which is then compiled by the compiler.

Text Editor

We write our program in a text editor. The file containing our program is called source file and is saved with a .cpp extension.

C++ Compiler

After saving our program in a file with the .cpp extension, we need to compile it to convert it into machine language that computer can understand.

Now let's see how to compile and execute a C++ program on different operating systems.

Writing and compiling C++ program on Windows

Though there are many IDEs available for editing and compiling C++ programs for Windows, here we are talking about editing and compiling program using DevC++ which allows us to edit, compile and run our program. We can write and save our program using DevC++ itself and then compile it using the same.

Before learning to write a program in DevC++, first, make sure it is installed in your computer. If not, then download and install it.

To write and compile in DevC++, follow the steps given below.

1. On opening DevC++, you will get a window. Click on File->New->Source File option.

4. To compile the program, type g++ hello.cpp -o hello ( g++ filename.cpp -o hello ) and press Enter. This will create an executable file with name 'hello' ( you can give any other name also but you will have to execute the file with that name only ).

5. To run your program, type ./hello ( 'hello' is the name of the executable file we created in step 4 ) and press Enter. This will show the output of your program.

You can see Hello World printed on your screen. Now, you know how to write and compile C++ codes. So, you can go to the next chapter to understand this code.