Loading Loading Medway Makers: Knowledge

Hello World

This little program has become the standard first example program that anybody writes in 'C'! Therefore it has become known as "Hello World".

Open a text editing program and create a new text file containing;

   #include <stdio.h>
   /* This is a comment */
   int main()
    printf("Hello world!\n");
    return 0;

And when you have finished save it in your home directory as "hello.c".

If your using a GUI such as Ubuntu then you just need to start a terminal and you will get a window with a prompt which is a $ for a normal user or a # for a root user, like this;


Type the text in this colour and press enter.

   tom$gold:~$ gcc -o hello hello.c

Now you may notice that this has compiled "hello.c" to create a new executable file called just "hello". Lets run it. Type the text in this colour and press enter.

   tom$gold:~$ ./hello

It should print out the message;

    Hello world!

That's it. You just ran your first 'C' program and it printed "Hello world".

A lot more on C programming can be found on the www.