Hello World! Program in C: First C Program


C Program To Print "Hello World!" Message On The Console Or Output Screen.

Let's begin your journey towards coding with the very first question of coding world.
Your task is to write code which prints Hello World.
Note: Use #include as header file where #include directive tells the compiler to include file and “stdio.h” is a file that tells the compiler to include all standard input/output library functions. Also use “printf” command to print the phrase.
Input:
You do not need to take any input for this problem.

Output:
"Hello World!" (without quotes).

Example Output:
Hello World!

//Code

/*
C program to print "Hello World!" message on the console or output screen.
Date: Monday, 07-September-2020
@author: Ankur Saxena
Platform: Linux Ubuntu 18.04 Lts / gcc 7.5.0 / Atom Text Editor
*/

#include <stdio.h>
#include <stdlib.h>

//main method or function
int main (){

  system ("clear");

  /* 'clear' command is used for clear the console screen.
  This commans is present inside the "stdlib.h" header file.
  In Windows machine, use "cls" command to clear the console.
  */

  //Print the "Hello World!" message
  printf("Hello World!\n");

  return 0;
}

Compile and Execute C Program
Let us see how to save the source code in a file, and how to compile and run it. Following are the simple steps −
·        Open a text editor and add the above-mentioned code.
·        Save the file as hello.c
·        Open a terminal / command prompt and go to the directory where you have saved the file.
·        Type gcc hello.c –o hello and press enter to compile your code.
·        If there are no errors in your code, the terminal / command prompt will take you to the next line and would generate hello.out executable file.
·        Now, type ./hello to execute your program. (Linux OS)
OR
Type hello to execute your program. (Windows OS)
·        You will see the output "Hello World!" printed on the screen.