Skip to content

building C apps 01. helloworld

create the code file

nano hello.c

        #include <stdio.h>
        void main()
        {
            printf("Hello World\n");
        }

compile to helloworld file

gcc hello.c -o hello

Executables have no extension in the unix world, because they are meant to be executed in the shell.
the reason , compare : cat file.txt | less versus cat.bin file.txt | less.bin
if you do decide to use a extention for some reason : use .bin => helloworld.bin

test / execute

./hello

basic principles

This code is incredibly straightforward , 1 line that print some text to the terminal.
yet , it already :

  1. includes the standard input-output library header (stdio.h)
    this library contains the IO functionality we need for talking with the command line.
  2. use the “main()” function.
    this function is always required and is called whenever the C program is run.
  3. Within this function, we make a call to “printf()” that will print the text “Hello World” to the terminal.

Nota, “\n” add a new line at the end of the text.