C/C++ Compilation Basics

Key Word(s): C++, compiling




Key: :large_orange_diamond: - Code Example :large_blue_diamond: - Code Exercise :red_circle: - Code Warning
Previous: C++ Track Overview
Next: Source & Header Files


Compilation Basics

(We will have more on this topic later in the semester.)

Within this track, we will need to compile our codes.
C and C++ are compiled programming languages contrasting Python which is an interpreted language.
Compiled languages are usually much faster than interpreted languages.


Compiling Hello, World!

Let's take a look at the canonical Hello, World! to learn the basics of compiling programs from source files.

:large_orange_diamond: hello.c

#include <stdio.h>

int main(void) {
  printf("Hello, World!\n");
  return 0;
}


Compiling on the command line:

:large_orange_diamond: Compiling with gcc

gcc -o hello hello.c


We can also compile the single file using make.

:large_orange_diamond: Compiling with make (simple version)

make hello


Executing on the command line:

:large_orange_diamond: hello Output

./hello
>>> Hello, World!


:large_orange_diamond: Sandbox Example: Hello World!


Next: Source & Header Files