Print: Hello World in C
/*Write your comment here*/ #include<stdio.h> #include<conio.h> void main() { clrscr(); printf("Hello World"); getch(); }
Program Description
This code is a simple C program that prints the message “Hello World” to the console. Here’s a breakdown of the code:
Lines 1-2:
C
#include<stdio.h> #include<conio.h>
These lines are called header inclusions. They include standard libraries containing pre-written functions that the program can use.
stdio.h
includes functions for standard input/output operations like printing to the console (printf
)<conio.h>
( Not recommended for modern C development ) includes functions specific to certain console environments, likeclrscr
(clear screen) andgetch
(get character).
Line 3:
C
void main()
This line declares the main
function, which is the entry point of the program. In C, execution always starts from the main
function.
Line 4:
C
clrscr();
This line calls the clrscr
function, which is supposed to clear the console screen. However, conio.h
is not part of the standard C library and might not be available on all compilers. It’s generally recommended to avoid using non-standard libraries for better portability.
Line 5:
C
printf("Hello World");
This line calls the printf
function from the stdio.h
library. It prints the message “Hello World” to the console screen.
Line 6:
C
getch();
This line calls the getch
function from conio.h
. It pauses the program execution and waits for the user to press a key. The pressed key’s character isn’t displayed on the screen (which is why it’s called getch
). Similar to clrscr
, getch
is not part of the standard C library and might not be portable.
Overall:
This code is a very basic example of a C program that demonstrates how to use standard input/output functions to print a message to the console. It’s a good starting point for learning C programming basics. However, it’s important to note that conio.h
is not recommended for modern C development due to portability issues. You can achieve similar functionality using platform-independent libraries or terminal control methods.