How to Write First C Hello World

In order to write our first C “Hello World” program first need to understand that C is structural language so certain structure need to follow while written code. C programs can be written in any text file but important is that extension of file should be “.c” – example as hello.c
We can use any editor to write C program , in Linux/Unix we can use “vi” editor to write C program and for Windows we can use sublime text.

First C Hello World Program

Our first C program – Save below content in

# include <stdio.h>
int main()
    printf("Hello World\n");
    return 0;

Lets understand below terms :

  • Preprocessor Commands
  • Functions
  • Library functions
  • Statement and Semicolon
  • Return statement

In above example #include<stdio.h> is a preprocessor command which tells a C compiler during compilation that include stdio.h
file in code. It is necessary to include some basic preprocessor directive in code to use basic built-in library functions.

Functions are main building blocks of C Program. It can have many functions in code but one mandatory function main() need to define in program. main() function is prefixed with return type in above example int used which means this function returns an integer value when program exist. If functions is not returning anything then void need to mention in begging of function. Will study function in details later.
Function definition need to start with “{“an end with “}” , it is mandatory to follow this syntax otherwise syntax error come during compilation.

C provides various in-build library functions . In above hello world program printf() is a built in function which is used to print contain on the screen. “Hello World” get displayed on console screen during execution on program. “\n” is newline due to which after Hello World statement newline get added on console.

Statement is instruction given to computer to do certain activity it could be output to console, input from keyboard, etc… printf(“Hello World”) is statement. Each statement needs to end with semicolon “;”. It is mandatory to have semicolon for each statement otherwise compilation issue occur.

Return statement is very important for any function, return keyword has to used in end of function. For main() we have defined int is return value so we have to return integer value along with return statement, therefore return 0 is used to return zero value to program.

In Linux using gcc , we can compile C program . In Window using Turbo C or Dev C++. By default a.out program generated and by executing we can see output

root#gcc hello.c
Hello World

In order to generate executable with particular fi le name then use -o option. Like below hello is binary fi le created during compilation.

root#gcc hello.c -o hello
Hello World

In conclusion, the “Hello World” program in C is widely regarded as a simple yet essential introduction to the syntax and structure of the C programming language, primarily aimed at beginners. This program is characterized by its demonstration of fundamental programming concepts such as the inclusion of libraries, the execution of the main function, basic input/output operations, and the usage of the return statement. By mastering this introductory program, learners are provided with a solid foundation in the basics of coding, which prepares them for more complex programming challenges. It is often celebrated for its role in building confidence and foundational knowledge among new programmers. As learners progress in their programming journey, the principles illustrated by the “Hello World” program remain a fundamental cornerstone, upon which more advanced skills are developed.

Leave a Comment

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

Scroll to Top