Compile C Hello World Program – POFTUT

Compile C Hello World Program

[rps-include post=6557]

Now we are here in start point. We will write a simple application which is generally a Hello World. This is very important because writing, compiling, running a C application is very important for beginners.

Hello World

Now our code is below. I have written this code very clear way line by line. This code provides basic structure of a C program.

  • #include <stdio.h> is a library which provides required functions for our program. Libraries provides functionalities required in applications. For example if we need some math functions like sin,cos etc. there is two way to solve this problem. One way is to implement these function by writing them scratch which is very tricky and time consuming job. Other way is using existing libraries those provides these as functions or other ways in a very efficient way.
  • int main() { … } is our programs entrance function. By default C applications starts running from main function. Here int is not important for us but we will look it future chapters.
  • /* I am C developer */ is not part of code it is called comment. Comments are not included in to program executable they are just resides in source code. Comments are very useful way to make our application readable and understandable.
  • printf("Hello, Poftut! \n"); is the actual code part here use use the function printf  and provide text which will be printed to the standard out put.


Now our code is ready to compile and create an executable. Compiling will convert our source code to an executable. Executable means a file that can be run on the Operating System. We will use gcc. First we save our code to a file named hello.c . And now we can simple call gcc like below by providing our source code file.

Now an executable file name a.out is create by gcc. We can simple run this file like below.

Set Name Of Executable File

As we see above created executable file is named a.out . This is an ugly way. In big projects this will fail the compilation. We can set a name for newly created executable file with -o parameter of gcc.

[rps-include post=6557]

1 Response

  1. steve says:

    this code fails as you are not returning an integer to the main function on exit, the final line of code should read:

    return 0;

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)