BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Hello World Program in C

Last Updated: September 22, 2017 by Chaitanya Singh | Filed Under: C Programs

Here we will write two C programs to display Hello World on the screen. In the first program we are displaying the message using printf function and in the second program we are calling a user defined function and that function displays the Hello World message on the screen.

Example 1: Displaying Hello World

#include <stdio.h>
int main()
{
   /* printf function displays the content that is
    * passed between the double quotes.
    */
   printf("Hello World");
   return 0;
}

Output:

Hello World

1. #include <stdio.h> – This statement tells compiler to include this stdio.h file in the program. This is a standard input output file that contains the definitions of common input output functions such as scanf() and printf(). In the above program we are using printf() function.

2. int main() – Here main() is the function name and int is the return type of this function. Every C program must have this function because the execution of program begins with the main() function. The 0 return value of this function represents successful execution of program while the return value 1 represents the unsuccessful execution of program. This is the reason we have return 0; statement at the end of this main function.

3. printf("Hello World"); – This function displays the content within double quotes as it is on the screen.

4. return 0; – As mentioned above, the value 0 means successful execution of main() function.

Example 2: Hello World Program using Functions

Lets see the same program using user defined function. In this program we have created a function hello() that prints the message on the screen. We are calling this function in the main() function. To understand user defined functions, read this guide: User Defined Function in C.

#include 
void hello(){
	printf("Hello World");
}
int main()
{
   //Calling a function here
   hello();
   return 0;
}

Check out these related C programs:

  1. C Program to print number entered by user
  2. C Program to check whether the number is even or odd
  3. C Program to arrange numbers in the ascending order

Top Related Articles:

  1. C Program to Read the First Line From a File
  2. C Program to concatenate two strings without using strcat
  3. C Program to Print an Integer entered by the user
  4. C Program to find greatest of three numbers
  5. C Program to read and print employee details using structure

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

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

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap