The C Hello World Program is the first and simplest program that beginners write while learning C. It introduces the basic structure of a C program and demonstrates how to display output on the console.
- It helps understand the basic structure of a C program (main(), headers, and statements).
- It introduces console output using the printf() function.
Prerequisites:
- Install a C compiler such as GCC or Clang.
- Use any C IDE or a text editor with a compiler.
Implementation of C Hello World
The following program prints "Hello, World!" on the console.
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
Output
Hello World
Understanding the C Hello World Program
1. Header File
The program begins by including the standard input-output library.
#include <stdio.h>
- stdio.h provides functions such as printf() and scanf().
- The preprocessor includes this header before compilation.
2. main() Function
Every C program starts executing from the main() function.
int main() {
// Statements
}
- int specifies that main() returns an integer.
- main() serves as the entry point of the program.
3. printf() Function
The printf() function displays text on the console.
printf("Hello, World!");
- It prints the given string exactly as written.
- It is declared in stdio.h.
4. return 0
return 0;
- Returns control to the operating system.
- 0 indicates successful execution.
Steps to Compile and Run a C Program
A C program is executed in two stages:
- Compilation (source code → executable)
- Execution (running the executable)
1. Compilation
The source file (.c) is compiled into an executable using a C compiler.
gcc HelloWorld.c -o HelloWorld
- gcc is the GNU C Compiler.
- -o HelloWorld specifies the executable name.
2. Execution
Run the generated executable.
Windows
HelloWorld.exe
Linux/macOS
./HelloWorld
Output
Hello, World!
Note: If the compiler is not recognized, ensure that GCC or another C compiler is installed and added to your system's PATH.