Breaking Down Hello World Program in C

Hello World Program

As we have already seen that, Hello, World! is a simple program in C. Its generally execute the string to display using the simple syntax of C. Let’s write it down again then we will see how “Hello, World!” program works.

You may rewrite the following code again in your favorite text editor then recompile it and finally execute it to make sure it is working or not.

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

Output:
Hello, World!

Code Explanation

In the Source Code, the first line “#include <stdio.h>” is actually a preprocessor. Here stdio stands for Standard Input Output/ Standard I/O and the file name extension .h indicates the header file. <stdio.h> tells the compiler to include the header file package by “#include” command to call the input/output basic function from the header package. We will learn about header file later on.
This <stdio.h> package containt the functions like printf() , scanf() and these types of basic function.

If you want to execute something in C programming language then you must have to use the main function. Remember that anything you want to execute, it may be either a calculation or a condition or a loop or displaying out a string or result you have to use the main function. In the writing method of the main function is int main(). Like the following:

int main() { //Your execution code goes here}

Next, in the main function, the 4th line uses the keyword “printf” that indicate the afterward commands will be displayed out, it can be either a String in a double quote or It also can out the value of a variable. We will learn more about data types in the later chapter. Here
printf("Hello, World!"); simply print the String message to the screen.

In the next line, the “return 0;” command tells the compiler to stop the function and program as well. In general, every time you starts a program you must have to end or stop that using the “return 0;” command.

« Previous Next »