Environment to write code:

We need an environment to write and compile(run) our C++ code. To write code, we need a text editor. To compile our code, we need a compiler. The compiler converts our code into machine understandable code.

Compiler:

Compiler translates instructions written in a high-level programming language into the equivalent machine code. There are many compilers which are available for use. As far as 2024, you should download g++ which will compile your C++ code into machine understandable code.

Integrated Development Environment (IDE):

The complete environment to write the code is IDE. IDE functions as an editor as well as a compiler. Some IDEs require compiler but some do not require. There are different IDEs available like:
  • Eclipse
  • Code Blocls
  • Dev C++
  • VS Code

These are all free and you can use any of these to run your code.

Note: There are many Integrated Development Environments (IDEs) which are available online but they have limited functionality. For better experience, you have to download IDEs listed above.


After setting up the environment, open the new file. Write the following code and save it with the extension ".cpp"


helloworld.cpp
#include <iostream>
using namespace std;

int main() {
    cout << "Hello, World! ";
    return 0;
}

Flowchart for Code Compilation:

flowchart

Explanation:

  • Source Code


    Source code is the code which is written in human readable programming language.

  • Preprocessor


    Preprocessor does file inclusion, macro substitution, conditional compilation etc. and after preprocessing, the code is sent to compiler for compilation.

  • Compiler


    The compiler compiles the code and and generate executable file. In case of interpreted languages an intermediate code can be used by the computer.

  • Assembler


    Assembler converts the assembly code into machine code. Assembler gives .obj file as output.

  • Linker


    Linker links static libraries with our machine code and makes it executable. Linker gives .exe file as output.

Components of C++ code:

The three main components of C++ code are:
  1. Header Files
  2. Main Function
  3. Return Statement

We will understand this code in the next chapter.
Your code should be error free so that it will execute without any error.