Following is a program to display “Hello World” in C programming.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(“Hello World”);
getch();
}
Output:
Hello World
Let’s break down the code step by step:
#include<stdio.h>
#include<conio.h>
These two lines are known as preprocessor directives. They include the necessary header files (stdio.h
and conio.h
) that contain standard input/output and console functions respectively. The stdio.h
header provides the printf
function for printing to the console, while conio.h
provides the clrscr
and getch
functions.
void main()
{
clrscr();
printf("Hello World");
getch();
}
The main
function is the entry point of the program. It has a return type of void
, which means it doesn’t return any value. The function body is enclosed within curly braces {}
.
Inside the main
function:
clrscr()
is a function provided by theconio.h
library, which clears the console screen.printf("Hello World");
is a function that prints the string “Hello World” to the console.getch()
is another function provided byconio.h
that waits for a key to be pressed before the program exits. It prevents the console window from closing immediately after displaying the output.
Note: The conio.h
header is not a standard part of the C language and is specific to certain compilers and operating systems (e.g., Turbo C). If you are using a different compiler or operating system, you may encounter an error related to conio.h
.