Compile: A computer can only understand machine code. A compiler can translate the C++ programs that we write into machine code. To compile a file, you need to type
g++ followed by the file name in the terminal:
The compiler will then translate the C++ program hello.cpp and create a machine code file called a.out.
Execute: To execute the new machine code file, all you need to do is type
./ and the machine code file name in the terminal:
The executable file will then be loaded to computer memory and the computer’s CPU (Central Processing Unit) executes the program one instruction at a time.
In our text editor, we have the Hello World program.
Click on the folder icon:
There should only be hello.cpp in there right now.
Compile hello.cpp using the terminal.
Click on the folder icon again. There should be a new a.out file in the folder, with some mysterious, alien-looking symbols inside.
We can’t understand this, but a computer can!
Execute a.out using the terminal.