C Hello World Program

Hello coders, today we will be learning how to write Hello World Program in C language. 

Almost every programmer starts their programming journey by the hello world Program. 

C Hello World Program

Hello, World! Program is the first step towards learning any programming language and it is also one of the easiest programs to write.

So, without further ado, let’s get to know about the C Hello World Program.

C Hello World Program

There are many ways to write the hello world program but in this tutorial we will mainly focus on two of them. The first one is by using printf function and the second one is by using a user defined function.

Both of the methods will display a hello world message on the Screen as output.

Method 1: Using printf() Function

#include <stdio.h>
int main(){
    // printf()function displays the string as output
    printf("Hello, World!");
    return 0;
}

Output

Hello, World!

Method 2: Using user defined Function

In this program, we will create a function hello() that will print the message on the screen. Then, we will call this function in the main function.

#include <stdio.h>
void hello(){
    printf("Hello, World");
}
int main()
{
    // calling the user defined function
    hello();
    return 0;
}

Output

Hello, World!

How Does the Hello World Program Work ?

#include <stdio.h> – In the first line we have used #include, it is a preprocessor command that tells the compiler to include the contents of the stdio.h(standard input and output) file in the program.

<Stdio.h> – The stdio.h is a file which contains input and output functions like scanf() and printf() to take input and display output respectively.

Int main() – Here main() is the function name and int is the return type of this function. The Execution of any Programming written in C language begins with main() function.

printf() – printf() is a library function which displays the strings under quotation marks to the screen.

return 0 – return statement ends the program after successful execution. Return value 0 represents the successful execution of the program while return value 1 represents the unsuccessful execution of the program. 

Note: Your program will not run if you have used printf() function in your program without writing #include<stdio.h>.

Conclusion

I hope you have understood how to write a hello world program in C. You are free to use any of the two methods.

If you have any query regarding this, feel free to contact in the comment Section. We will be delighted to help you.

Also Read:

Leave a Comment

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