Hello World Program
Mar 282021

Hello World Program in C

0 Suresh Chand March 28, 2021

Here, We are printing the Hello World using C program in two way.

  • First Program: In this program, We will print the Hello World program using printf function.

In both program, We will just print Hello World message on the screen.

Example 1: Program using printf function

#include <stdio.h>

int main(){
    /*
    * printf function print the message on the screen 
    * that is present inside the double quote
    */
    printf("Hello World");
    return 0;
}

The output of the above program is Hello World.

Let’s discuss all the lines of the above program in detail.

1. Comments

Here we can see two types of comments in the above program. Comments are the explanation or description of source code that does not affect your program logic in any way. Comments are neglected by compilers or interpreters.

/*
* printf function print the message on the screen 
* that is present inside the double quote
*/

2. #include <stdio.h>

This statement tells the compiler to include stdio.h from the library. This library contains input-output functions such as printfscanf, etc.

4. init main()

This is the main function of our program from where the program start to execute. int means the return type of that function which tells the compiler that this function return integer type value.

5. printf(“Hello World”)

printf is a function that is presented in stdio.h library. The objective of this is to print the statement as a output. This function print inside the value included in the double quote (“”) and it also can display variable values. 

6. return 0

This statement return 0 value from main function which state that execution is completed. return 1 state that execution is failed.

Example 1: Program using a user-defined function

#include <stdio.h> 
void hello_world(){
    printf("Hello World");
}
int main(){
   //We are calling the function to print hello world
   hello_world();
   return 0;
}

This is the same as the above program. The only difference is that It uses a user-defined function to display the message. We have defined the hello_world function and then called inside the main function. If you are unfamiliar with a user-defined function, then read about a user-defined function.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Join Our Newsletter Now

Get the latest tutorials, examples and projects updates.

Ads Block Detector Powered by codehelppro.com

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Disable Ad Block

Want Same System