Hello World Program in C

By | February 25, 2024

In this article, you will learn to print “Hello, World!” on the screen in C programming. Most students of programming languages, start from the famous ‘Hello World’ code. This program prints ‘Hello World’ when executed.

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: Using printf function

// simple C program to display "Hello World !" 
#include <stdio.h>
int main()
{
   // using printf function 
   // printf is defined in stdio libary 
   printf("Hello World !");
   return 0;
}

Output :

Hello World ! 

Notes –

  1. Compiler includes the contents of stdio.h (standard input and output) file in the program using #include preprocessor.
  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.
  3. Functions of stdio.h are scanf() and printf() to take input and display output respectively.
  4. If you use the printf() function without writing #include , the program will not compile.
  5. The program ends with return 0; statement. It means “Exit status” of the program. The value 0 means successful execution of main() function.

Example-2: Using user defined function

// simple C program to display "Hello World !" 
#include <stdio.h>
void hello();

// to print Hello World !
void hello(){
    
	printf("Hello World !");
}
int main()
{
   // call this function
   hello();
   
   return 0;
}

Output :

Hello World ! 

Note –
This program is also uses printf() but inside a function.



Please write comments if you find anything incorrect. A gentle request to share this topic on your social media profile.