For working professionals
For fresh graduates
More
5. Array in C
13. Boolean in C
18. Operators in C
33. Comments in C
38. Constants in C
41. Data Types in C
49. Double In C
58. For Loop in C
60. Functions in C
70. Identifiers in C
81. Linked list in C
83. Macros in C
86. Nested Loop in C
97. Pseudo-Code In C
100. Recursion in C
103. Square Root in C
104. Stack in C
106. Static function in C
107. Stdio.h in C
108. Storage Classes in C
109. strcat() in C
110. Strcmp in C
111. Strcpy in C
114. String Length in C
115. String Pointer in C
116. strlen() in C
117. Structures in C
119. Switch Case in C
120. C Ternary Operator
121. Tokens in C
125. Type Casting in C
126. Types of Error in C
127. Unary Operator in C
128. Use of C Language
Writing your first C program is a milestone for every beginner in programming. The C Hello World Program is the simplest way to get started with the C language. It introduces you to essential concepts like syntax, functions, and compilation.
In this article, we will go through the step-by-step process of writing, compiling, and running this basic program. By the end, you will have a solid understanding of how a C program works. You can also explore our in-depth Software engineering courses.
The C Hello World Program is the first step in learning C programming. It prints the message "Hello, World!" to the output screen. This program is often the first step in learning C because it introduces the basic structure and syntax of the language without involving complex logic.
If you are new to C programming, then you must explore the Features of C Language article.
Also demonstrating how to display output on the console and helps you understand the basic structure of a C program. This program also introduces the main() function, printf() function, and header files, which are essential components of any C program.
Also Explore: Functions in C
Must Explore: History of C Language
Before writing and executing a C Hello World program, you need to set up a proper C programming environment on your computer. This involves installing a compiler, a text editor or IDE (Integrated Development Environment), and configuring your system for smooth execution.
A compiler converts your C code into an executable program that the computer can run. The most widely used compiler for C is GCC (GNU Compiler Collection).
1. Download and install MinGW (Minimalist GNU for Windows) or TDM-GCC from their official websites.
2. During installation, select the GCC Compiler option.
3. After installation, open Command Prompt and type:
gcc --version
4. If installed correctly, it will display the GCC version.
1. Open Terminal and install the Xcode command-line tools by running:
xcode-select --install
2. Once installed, verify by running:
gcc --version
3. This confirms that the Clang-based GCC compiler is installed.
1. Open Terminal and install GCC using:
sudo apt update
sudo apt install gcc
2. Verify installation:
gcc --version
To write C code, you need a text editor or an IDE (Integrated Development Environment).
For beginners, Code::Blocks is highly recommended as it comes with a built-in compiler and an easy-to-use interface.
To run C programs from the command line, you need to add the GCC path to system environment variables.
For efficient debugging, install GDB (GNU Debugger):
For in-depth explanation read the C Language Download article!
Here is a simple C Hello World Program:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
#include <stdio.h>
int main() {
printf("Hello, World!\n");
Example Without \n
printf("Hello, ");
printf("World!");
Output:
Hello, World!
(Both words appear on the same line.)
Example With \n
printf("Hello, \n");
printf("World!\n");
Output:
Hello,
World!
(\n moves "World!" to the next line.)
return 0;
When you run the program, the execution happens as follows:
Must Explore: 29 C Programming Projects in 2025 for All Levels [Source Code Included]
After writing the program, you need to compile and run it.
This will display:
Hello, World!
Apart from the standard method, here are three other ways to write the C Hello World Program:
#include <stdio.h>
int main() {
char message[] = "Hello, World!";
printf("%s", message);
return 0;
}
#include <stdio.h>
int main() {
char *message = "Hello, World!";
printf("%s", message);
return 0;
}
#include <stdio.h>
void printMessage() {
printf("Hello, World!");
}
int main() {
printMessage();
return 0;
}
Each of these methods achieves the same output but showcases different ways of handling strings in C.
Avoiding these mistakes ensures smooth compilation and execution of your program.
After mastering the C Hello World Program, you should explore more fundamental concepts in C:
Practice regularly and build small projects to enhance your understanding.
The C Hello World Program is more than just a simple introduction—it is the foundation of C programming. It helps you understand essential concepts like syntax, functions, and program execution. By mastering this fundamental program, you build the confidence needed to write more complex C programs.
This knowledge sets the stage for exploring advanced topics such as data structures, file handling, and memory management. As you continue your C programming journey, focus on writing clean, efficient code, and always practice to improve your skills. Keep learning, experimenting, and refining your understanding to become a proficient C programmer!
The C Hello World Program is a simple program that prints "Hello, World!" on the screen. It serves as the first step in learning C programming by introducing basic syntax, functions, and program structure.
This program helps beginners understand fundamental C concepts like header files, functions, compilation, and execution. It also serves as a starting point for learning variables, loops, and memory management.
To write and execute this program, you need:
A basic C Hello World Program consists of:
#include <stdio.h> // Header file for input-output functions
int main() {
printf("Hello, World!\n"); // Prints output
return 0; // Indicates successful execution
}
#include <stdio.h> is a preprocessor directive that includes the Standard I/O Library, enabling functions like printf() for displaying output.
Every C program must have a main() function because it is the entry point from where execution begins.
This statement uses the printf() function to print "Hello, World!" on the screen. The \n at the end adds a newline, moving the cursor to the next line.
The return 0; statement signals to the operating system that the program executed successfully. It is a best practice in C programming.
Windows (GCC in Command Prompt):
gcc hello.c -o hello.exe
hello.exe
Linux/macOS:
gcc hello.c -o hello
./hello
After running, the output will be:
Hello, World!
Apart from the standard method, here are three variations:
Using a character array:
char message[] = "Hello, World!";
printf("%s", message);
Using a pointer to a string:
char *message = "Hello, World!";
printf("%s", message);
Using a function:
void printMessage() {
printf("Hello, World!");
}
printMessage();
Each method achieves the same result but demonstrates different string handling techniques.
Some common errors include:
Mastering the Hello World program lays the foundation for understanding:
Printing "Hello, World!" is a universal tradition in programming. It is used across languages like C, Python, Java, and JavaScript as an introductory example to learn syntax and execution flow.
Take a Free C Programming Quiz
Answer quick questions and assess your C programming knowledge
Author
Start Learning For Free
Explore Our Free Software Tutorials and Elevate your Career.
Talk to our experts. We are available 7 days a week, 9 AM to 12 AM (midnight)
Indian Nationals
1800 210 2020
Foreign Nationals
+918068792934
1.The above statistics depend on various factors and individual results may vary. Past performance is no guarantee of future results.
2.The student assumes full responsibility for all expenses associated with visas, travel, & related costs. upGrad does not provide any a.