Hello World Program in C

The "Hello World" program is one of the simplest programs you will learn, and it also serves as the initial step in learning any programming language. Simply showing the message "Hello World" on the screen will do the trick. Let’s explore the program and attempt to comprehend the syntax used within it.

C program to print Hello World!

// Simple C program to display "Hello World"  
#include <stdio.h> // Header file  
int main() // main function where the execution starts
{    
    printf("Hello World!"); // print hello world  
    return 0;
}
Output:
Hello World!

Let’s see how the Hello World program in C works, we will discuss line-by-line execution of the hello world program in C.

  • #include< stdio.h >: The preprocessor statement #include instructs the compiler to include the contents of the stdio.h (standard input and output) file.
  • Functions like scanf() and printf() that accept input and show output, respectively, are included in the stdio.h file.
  • The program will not build if the printf() method is used without adding #include stdio.h>.
  • The main() function is where a C program begins to run.
  • A library function called printf() is used to display formatted output on a screen. printf() in this program prints the string Hello, World! on the screen.
  • Both the opening braces ‘{‘ and the closing braces ‘}’ denote the start and end of the main function, respectively. The blocks, which include everything in between these two, make up the primary function’s body.
  • The program’s "Exit status" is indicated by the return 0; statement. The program closes with this sentence, to put it simply.

As you can see, the return statement and printf have been indented or shifted to the right. To make the code easier to read, this is done. It may not seem important in a program like Hello World, but when the program gets more complicated, it makes the code easier to understand and less prone to mistakes. Therefore, to make the code more legible, indentations and comments must always be used.

Other C Programs

C Program for Binary Search
C Program to Add Two Numbers
C Program to Calculate Percentage of 5 Subjects
C Program to Convert Binary Number to Decimal Number
C Program to Convert Celsius to Fahrenheit
C Program to Convert Infix to Postfix
C Program to Find Area of Circle
C Program to Find Roots of Quadratic Equation
C program to Reverse a Linked List
C program to reverse a number
Ascending Order Program in C
Menu Driven Program For All Operations On Doubly Linked List in C
C Program for Armstrong Number
C Program For Merge Sort For Linked Lists
C program for performing Bubble sort on Linked List
Perfect Number Program in C
Leap Year Program in C
Odd Even Program in C
Selection Sort Program in C

Leave a Reply

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