Hello World Program in C

Hello World! in C Programming. Here we will write the Hello world program in C language. In every programming first program example starts from displaying Hello, World! to the screen.

#include<stdio.h>
int main()
{
   printf("Hello, ");
   printf("World!");
   return 0;
}

In the above program, both words are displayed on the screen separately. We can write Hello, World! in a single line or in multi-lines.

#include<stdio.h>
int main()
{
   printf("Hello, World!");
   return 0;
}

Output:-

Hello, World!


How Hello world program in C language works?

The first line of the program

#include<stdio.h>

The first line of the program, #include<stdio.h> is a preprocessor command. Preprocessor commands tell the compiler to include information about the included header file. Here we are including the header file “stdio.h” in the program, so the compiler will include the information about the standard input/output library. In most (99%) of the C program, you will find this header file.

The second line of the program

int main()

The main() is a function. Every function does some specific task. In C language main is defined to be a function that excepts no arguments, which is indicated by (). Note that the execution of a C program starts from the main() function. We can’t write any C program without the main function.

The third line of the program

printf("Hello, World!");

The statements of a function are enclosed in braces {}. Here, the main function contains only one statement, printf(“Hello, World\n”);

The printf is a library function that prints the output. The main function calls library function printf to print the sequence of characters. If, we use printf() function without writing #include <stdio.h>, the program will not be compiled, because printf() function is defined inside “stdio.h”

The printf() is a library function to send formatted output to the screen, it displays the string inside the quotation. In this program, the printf() displays Hello, World! text on the screen.

A sequence of characters in double-quotes, like “Hello, world! \n”, is called character string or string constant.

The sequence n in the string is a newline character, which prints output to the left margin on the next line. printf never supplies a new line automatically.

The fourth line of the program

return 0;

The return 0; statement is the “Exit status” of the program. In simple terms, the program ends with this statement.


Excercise

Solve these programming questions. Write, compile and execute the program and later compare it with the given solution.

Programming Question 1:- Display the below line to the screen

Welcome to the programming World.
Congratulations.

Solution:-

#include<stdio.h>
int main()
{
     printf("Welcome to the programming World.\n");
     printf("Congratulations.");
     return 0;
}

Programming Question 2:- Display your full name, Course name, and birthdate in a separate line. For example,

Name: Rocco Jerry
Course Name: Computer Science
Birthdate: 25 Jan 1995

Solution:-

#include<stdio.h>
int main()
{
     printf("Name: Rocco Jerry\n");
     printf("Course Name: Computer Science\n");
     printf("Birthdate: 25 Jan 1995");
     return 0;
}

Programming Question 3:- Display the below shape to the screen.

*****
****
***
**
*
**
***
****
*****

Programming question 3 solution:-

#include<stdio.h>
int main()
{
     printf("*****\n");
     printf("****\n");
     printf("***\n");
     printf("**\n");
     printf("*\n");
     printf("**\n");
     printf("***\n");
     printf("****\n");
     printf("*****");
     return 0;
}

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Similar basic C programming examples

Leave a Comment

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