What is "Hello World" program?
"Hello World" program is a simple conventional program used by programmers to demonstrate the basic syntax of a programming language. It typically consists of a piece of programming code that prints the phrase "Hello World" to the output (console).
In C, "Hello World" program is used to demonstrate the basic syntax of C and display (print) the phrase "Hello World" on the console.
Creating Hello World Program in C
-
Create a C file (with
.c
file extension) and open the file in your favorite C code editor. -
Add
#include <stdio.h>
at the top of the file. This code is used to include the standard input-output header file stdio.h , which contains functions for input and output operations in C. -
Add
int main() { }
function. This is the starting point of the program and C code blocks are placed inside the curly braces {} of main function. Every C program must have a main() function, and execution of the program begins from here. -
Add
printf("Hello World!");
C code inside the curly braces of main function.printf()
is a built-in function of stdio.h header file. The string "Hello World!" will be displayed. You can add your preferred text instead of "Hello World!". -
Add
return 0;
. It indicates the end of the main() function.
xxxxxxxxxx
#include <stdio.h>
xxxxxxxxxx
#include <stdio.h>
int main() {
//C code blocks are placed here
}
xxxxxxxxxx
#include <stdio.h>
int main() {
printf("Hello World!");
}
xxxxxxxxxx
#include <stdio.h>
int main() {
printf("Hello World!");
return 0;
}
We have completed the C hello world program. Hello World! will be displayed as output when the program is executed. Please take a closer look at the following example:
Complete Code of C Hello World Program
xxxxxxxxxx
#include <stdio.h>
int main() {
printf("Hello World!");
return 0;
}
Output of the above example
Hello World!