How to print "Hello World" in C

What is "Hello World" program?

"Hello World" program is a simple conventional program used by programmers to demonstrate the basic syntax of a programming language. It typically consists of a piece of programming code that prints the phrase "Hello World" to the output (console).

In C, "Hello World" program is used to demonstrate the basic syntax of C and display (print) the phrase "Hello World" on the console.

Creating Hello World Program in C

  1. Create a C file (with .c file extension) and open the file in your favorite C code editor.
  2. Add #include <stdio.h> at the top of the file. This code is used to include the standard input-output header file stdio.h , which contains functions for input and output operations in C.
  3. Add int main() { } function. This is the starting point of the program and C code blocks are placed inside the curly braces {} of main function. Every C program must have a main() function, and execution of the program begins from here.
  4. Add printf("Hello World!"); C code inside the curly braces of main function. printf() is a built-in function of stdio.h header file. The string "Hello World!" will be displayed. You can add your preferred text instead of "Hello World!".
  5. Add return 0;. It indicates the end of the main() function.

We have completed the C hello world program. Hello World! will be displayed as output when the program is executed. Please take a closer look at the following example:

Complete Code of C Hello World Program


Output of the above example

Hello World!
Note: Every statement in C should be terminated by a semicolon(;), including variable declarations, function calls, assignments, loops, conditionals, etc.

Live Code Playground

In the following C code editor, you can practice the above code by updating or adding more string (text) to the printf() function. Click the 'Execute Code' button to execute the code; the executed output will be displayed in the following C Code Output frame. Practice until you become comfortable and proficient with your code.

C logo C Online Editor
C Code Output