1. Objective
The goal of this program is to display the message Hello, World! on the computer screen.
It is traditionally the very first program written when learning any new programming language because it checks that:
The compiler is installed correctly.
You can write, compile, and run a simple program.
2. Full Source Code
Line-by-Line Explanation
| Line | Explanation |
|---|---|
// Print Hello, World! |
Comment: Anything after // is ignored by the compiler. It is used to describe what the code does. |
#include <stdio.h> |
Preprocessor Directive: Loads the Standard Input/Output library, which provides the printf function. |
#include <conio.h> |
Header File: Belongs to older DOS/Turbo C compilers. Provides functions like clrscr() and getch(). Not part of modern C standards. |
void main() |
Main Function: Program execution starts here. void means it does not return a value. Modern C prefers int main(). |
{ ... } |
Curly Braces: Mark the beginning and end of the main function’s body. |
clrscr(); |
Clear Screen: Erases the console output. Works only in Turbo C/older compilers. |
printf("Hello, World!"); |
Print Statement: Displays text on the screen. Use \n for a new line. |
getch(); |
Get Character: Waits for a key press before the program closes. Useful in DOS environment. |
4. Key Concepts Learned
Preprocessor Directives – #include statements import libraries before compilation.
Functions – Blocks of code that perform tasks. main() is the entry point.
Console I/O – Using printf to display text.
Comments – Improve readability and documentation.
