Posted: . At: 8:03 PM. This was 10 years ago. Post ID: 7316
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.

The simplest hello world program you can write in C.

This is a very simple Hello World program that you can write in C.

int main (void) {
 
    write (1, "Hello World\n", 14);
    return 0;
}

Just compile the program like this:

localhost% cc minimal.c -o small
minimal.c: In function ‘main’:
minimal.c:2:5: warning: implicit declaration of functionwrite[-Wimplicit-function-declaration]
     write (1, "Hello World\n", 14);
     ^~~~~

Then execute it to get the output. This is very easy.

localhost% ./small 
Hello World

This little program is very small indeed.

localhost% ls -hula ./small 
-rwxr-xr-x. 1 jason jason 8.4K May 25 09:28 ./small

I wonder if you could strip this program down even more and make it even simpler. An interesting exercise indeed.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.