Hello World in C and C++ (Beginner Guide)
If you are starting with C or C++, the first program you will write is the classic Hello World. This guide shows simple examples in both languages and explains how to run them.
What is a Hello World Program?
A Hello World program is the simplest way to test if your development environment is working. It prints a message to the screen.
Hello World in C
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
Hello World in C++
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
How to Compile and Run
Compile C program:
gcc hello.c -o helloRun:
./helloCompile C++ program:
g++ hello.cpp -o helloRun:
./helloCommon Errors
- Missing semicolon
- Wrong compiler (gcc vs g++)
- Incorrect file extension
FAQ
Why is Hello World important?
It confirms your compiler and environment are working correctly.
Can I run this on Windows?
Yes, using tools like MinGW or WSL.
Also read: How to optimize Windows performance