< All Topics

Write a C program to display “Hello World” on the screen.

In this article, we will learn how to write a C program to display “Hello World” on the screen. This is a simple program that can be used to demonstrate the basic syntax and structure of C language.

What we need?

To write a C program, we need a text editor and a compiler. A text editor is a software that allows us to write and edit the source code of our program. A compiler is a software that converts the source code into an executable file that can be run by the computer.

The first step is to create a new file in our text editor and save it with a .c extension. For example, we can name our file ezyfirst.c. The .c extension indicates that the file contains C source code.

The second step is to write the source code of our program. A C program consists of one or more functions, which are blocks of code that perform specific tasks. The main function is the starting point of the program, where the execution begins.

To display “Hello World” on the screen, we need to use the printf function, which is a built-in function that prints a formatted string to the standard output device, usually the monitor. The printf function takes one or more arguments, which are enclosed in parentheses and separated by commas. The first argument is a string literal, which is a sequence of characters enclosed in double quotes. The string literal can contain special characters, such as \n for a new line or \t for a tab. The other arguments are optional and can be used to insert values into the string literal using placeholders, such as %d for an integer or %f for a float.

The syntax of the printf() function is:

printf("string literal", optional arguments);

To display “Hello World” on the screen, we can write:

printf("Hello Computer\n");

The \n at the end of the string literal creates a new line after printing the message.

Full code of program

Here is one possible way to do it:

// my frst c program 
#include <stdio.h>

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

This program includes the standard input/output header file stdio.h and defines the main function. The printf function prints the string “Hello World” followed by a newline character \n to the standard output. The return 0 statement indicates that the program exits successfully.

The third step is to compile and run our program. To compile our program, we need to use the command line interface of our compiler and specify the name of our source file as an input and the name of our executable file as an output. For example, if we are using GCC compiler on Windows, we can type:

gcc hello.c -o ezyfirst.exe

This command will create an executable file named ezyfirst.exe in the same directory as our source file. After this your output will be displayed.

Hello World

To run our program, we need to execute the executable file from the command line or double-click on it from the file explorer. When we run our program, we should see “Hello Computer” displayed on the screen.

Congratulations! You have successfully written your first C program.

Recommended Readings

Leave a comment

Table of Contents