Writing and Understanding First C program – helloworld.c

Lets write a first C program which normally would be “helloworld” as,

$ vim helloworld.c
#include <stdio.h>

int main(void) {
        printf("Hello World \n");
        return 0;

Above we written simple and first C program, the standard structure of this C program normally is like below,


return_type main(void) {
       return success/failure;

Every C program contains minimum 3 sections as,

  • Header
  • main
  • Body

Header – is where all the header .h files are included.
.h header files contains the declarations of the functions using in the program. Here, we used function “printf” which is declared in stdio.h and defined in c library libc.

main – is the entry point of every C program.
Every C program should contain one main for program execution.

The syntax adjacent to main is like below,
return data type” main (void)
– return data type for main is “int” and it is used to indicate success or failure of the program execution. In above program “return 0″ is related to return data type” which returns integer 0.

void inside main(void) indicates main doesn’t accept any parameters right now from command line, but there are ways to accept command
line arguments using argc & argv to main which we will see later.

body – body of a “C” program can be anything from a single printf to a complex program which is defined in side open&close
curly brace { … body … }
NOTE: Every statement inside body ends with “semicolon” “;”

printf(“Hello World \n”);
here, this function “printf” prints the string “Hello World” on to the terminal.
“\n” – indicates go to new line, so using within printf it prints strings and goes to new line, which makes displaying of output on terminal look good.

Leave a Comment