C Hello World Program

“The story of life is quicker than the blink of an eye, the story of love is hello, goodbye” Jimi Hendrix

Let’s write a simple C program that shows the message “Hello World!” on Console/ Terminal of your operating system.

Note: The goal of this section is to just show you how a simple C program look like and what is the process of compiling and running such program. So don’t worries about the code used in this section and just simply follow the instructions for now.

In later sections we will dive deep into the details of the C codes and explain all the parts one by one.

Instructions of running a simple C program:

  1. Open a word-editor like Notepad (or any IDE that introduced in
    ide-section).

  2. Copy the code below and paste it into the editor:

#include <stdio.h>

int
main() {
printf("Hello World!" );
return 0;
}
  1. Now save the file with any name you like but the extension should
    be `.c`. For example: hello.c

G:hackC C++My C Language Tutorial�9-quick-example1.png
  1. Now open a new command prompt / terminal and go to the directory
    where this file exists and run the `gcc hello.c` command.

Note: the name “hello” in the command above is the name of the file and so if you’re using another name; make sure you replace the name “hello” with the one you selected.

G:hackC C++My C Language Tutorial�9-quick-example2.png
  1. Now hit the “Enter” and you’ll see something like this:

G:hackC C++My C Language Tutorial�9-quick-example3.png

Which means your source code is compiled and ready for running!

Note: By checking the directory of the source code you’ll see another file is added with the .exe as the extension (in windows operating system) and that is the compiled version of your source code!

  1. Now all you need to do, is to call the compiled file name in the
    command-prompt/ terminal in order to run the program:

G:hackC C++My C Language Tutorial�9-quick-example4.png

Congratulation! You just compiled and ran your first C program.