Hello World Program in C: Printing “Hello World” is the first step we follow in learning any programming language. It introduces us to various terminologies associated with a programming language.
Write a C program to print “Hello World”.
1. Include the necessary header files for printing.
2. Declare the main function for program execution.
3. Inside the main function, print “Hello World”.
There are various ways to print “Hello World” in the C language. Let’s explore the different approaches for printing “Hello World” in C.
In this approach, we print Hello World simply inside the main() function.
Here is the source code of the C program for printing “Hello World” in the main() function. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/* * C program to print “Hello World” */ #include <stdio.h> //main function int main() { //print Hello World printf("Hello World"); return 0; }
1. #include<stdio.h>:
- #include is a preprocessor command that loads the header file stdio.h.
- stdio.h is a header file that contains scanf() and printf() functions for input and output respectively.
2. int main(): used to declare a function main of integer return type. The execution of the program starts from the main() function.
3. printf(“Hello World”): printf() function is an inbuilt library function that is used to display output on the screen. The message Hello World will be displayed on the screen.
4. return 0: This is an exit statement. This line simply ends the program.
In this case, we are just printing “Hello World”.
Hello World
In this approach, we print Hello World using functions.
/* * C program to print “Hello World” using function. */ #include <stdio.h> //function print() to print Hello World void print() { printf("Hello World"); } //main function void main() { print(); // calling the function print() }
1. All the terminologies used here is same as the method 1.
2. The only difference is, instead of printing Hello World in the main function we created a function named print where we printed the Hello World.
3. The program execution always starts from the main() function so the function print() is called from the main function to execute and print Hello World.
4. The print() function is of void return type which means it does not return any value to the main function.
Hello World
To practice programs on every topic in C, please visit “Programming Examples in C”, “Data Structures in C” and “Algorithms in C”.
- Watch Advanced C Programming Videos
- Check C Books
- Check Computer Science Books
- Practice BCA MCQs
- Apply for C Internship