C Hello World Program

Hello readers, today we will be learning how to write a simple Hello World program using C Programming language.

C Hello World Program

Hello World Program is one of the simplest programs used to understand the syntax and structure of any new programming language. The motive of this program is to know the basic pre-requirements to write a program in C Programming language.

This program will simply display a “Hello, World!” message on the screen. We will perform this task using the following methods:

  1. Using Standard Method
  2. Using Functions

So, Without further ado, let’s begin this tutorial.

C Hello World Program

C Program

// C Hello World Program
#include <stdio.h>
int main(){

    // Displays message on the screen
    printf("Hello, World!");
    return 0;
}

Output

Hello, World!
C Program to Print Hello World

#include <stdio.h> – The #include is a preprocessor command that tells the compiler to include this stdio.h file in the program. The stdio.h is a header file which contains the basic functions such as scanf() and printf() to take input and display the output respectively.

int main() – This is where the execution of the program starts. Every C program must contain this function because execution of the program begins with int main() function. Here, int tells the user that the program is returning some value.

printf(“Hello, World!) printf() is a library function used to display output on the screen. The strings should be in double quotes in order to display the message.

return 0 – The 0 return value represents the successful execution of the program while 1 represents the unsuccessful execution of the program. The program ends with this statement.

C Program to Print Hello World Using Functions

C Program

// C Program to Print Hello World Using Functions
#include <stdio.h>
void hello(){
    printf("Hello, World!");
}

int main(){

    // Calling out function
    hello();
    return 0;
}

Output

Hello, World!
C Program to Print Hello World Using Functions
void hello(){
    printf("Hello, World!");
}

In this program, we have defined a custom function named hello which returns “Hello, World” message.

int main(){

    // Calling out function
    hello();
    return 0;
}

Then, we call the custom function hello in the main function to display the message as output.

C Program to Print Hello World Multiple Times

C Program

// C Program to Print Hello World Multiple Times
#include <stdio.h>
int main(){
    int i;

    for (i  = 1; i <= 5; i++){
        printf("Hello, World!\n");
    }
    return 0;
}

Output

Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
C Program to Print Hello World Multiple Times
   int i;

In this program, we have declared an int data type variable named i.

    for (i  = 1; i <= 5; i++){
        printf("Hello, World!\n");
    }

Then, we used for loop to print the message on the screen 5 times.

Conclusion

I hope after reading this post, you understand how to write a simple “Hello, World” program using C Programming language.

Don’t forget to put your queries in the comment section, we will be delighted to solve your query.

Leave a Comment