Learn
Compile & Execute
Compile and Execute

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:

g++ hello.cpp

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:

./a.out

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.

Instructions

1.

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.

2.

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.

Folder Icon

Take this course for free

Already have an account?