Like in most of the programming languages, program to write the text "Hello, World!" is treated as the first program to learn in C. This step-by-step guide shows you how to create and run your first C program.
Step 1: Setting Up Your Environment
Before proceeding to write the first program, the user needs to set up a C program compiler, which would compile and execute the first program. Here we have used a Windows-based GCC compiler to compile and run the program. To know more on how to set up the local GCC compiler or run using online ide refer to Setting C Development Environment.
Step 2: Creating a Source Code File
This requires writing the "Hello World" program, in a text editor and saving the file with the extension .c, for example, we have stored the program in a C-type file HelloWorld.c.
HelloWorld.c
// Simple C program to display "Hello World"
// Header file for input output functions
#include <stdio.h>
// main function -
// where the execution of program begins
int main() {
// prints hello world
printf("Hello World");
return 0;
}
Step 3: Navigating to the Source Code Directory in Terminal or Command Prompt
This includes opening CMD or command prompt line and navigating to the directory where the file HelloWorld.c is present.
For Example,
cd C:\Users\Chin\Sample
Step 4: Giving GCC Compiler to Generate the Executable File
To compile the code execute the following command:
gcc HelloWorld.c
This would create a C-executable file with a random name given by the compiler itself. We got the executable filename as a.

To give a user-oriented name, run the following command:
gcc -o helloworld HelloWorld.c
This would create a C-executable file by the name helloworld.
Step 5: Run the Executable File
To run the executable file to get the result, run the following command:
helloworld

Explanation of the Code
Let us now understand the terminologies of the above program:
Line 1:
// Simple C program to display “Hello World”
- This is a single comment line. A comment is used to display additional information about the program.
- A comment does not contain any programming logic as it is not read by the compiler. When a comment is encountered by a compiler, the compiler simply skips that line of code.
- Any line beginning with ‘//’ without quotes OR in between /*…*/ in C is a comment.
More on Comments in C
Line 3:
#include
- In C, all lines that start with the pound (#) sign are called directives. These statements are processed by preprocessor program invoked by the compiler.
- The #include directive tells the compiler to include a file and #include<stdio.h> tells the compiler to include the header file for the Standard Input Output file which contains declarations of all the standard input/output library functions.
More on Preprocessors in C.
Line 6:
int main()
- This line is used to declare a function named "main" which returns data of integer type. A function is a group of statements that are designed to perform a specific task. Execution of every C program begins with the main() function, no matter where the function is located in the program. So, every C program must have a main() function and this is the function where the execution of the program begins.
- { and }: The opening braces '{' indicates the beginning of the main function and the closing braces '}' indicates the ending of the main function. Everything between these two comprises the body of the main function and are called the blocks.
More on main() function in C.
Line 10:
printf("Hello World");
- This line tells the compiler to display the message "Hello World" on the screen. This line is called a statement in C. Every statement is meant to perform some task. A semi-colon ';' is used to end a statement. The semi-colon character at the end of the statement is used to indicate that the statement is ending there.
- The printf() function is used to print a character stream of data on the stdout console. Everything within " " is displayed on the output device.
More on Input/Output in C.
Line 12:
return 0;
- This is also a statement. This statement is used to return a value from a function and indicates the finishing of a function. This statement is basically used in functions to return the results of the operations performed by a function.
- Indentation: As you can see the printf and the return statement have been indented or moved to the right side. This is done to make the code more readable. In a program as Hello World, it does not seem to hold much relevance but as the program becomes more complex, it makes the code more readable and less error-prone. Therefore, one must always use indentations and comments to make the code more readable.
Similar Reads
C Programming Language Tutorial C is a general-purpose mid-level programming language developed by Dennis M. Ritchie at Bell Laboratories in 1972. It was initially used for the development of UNIX operating system, but it later became popular for a wide range of applications. Today, C remains one of the top three most widely used
5 min read
C Language Introduction C is a general-purpose procedural programming language initially developed by Dennis Ritchie in 1972 at Bell Laboratories of AT&T Labs. It was mainly created as a system programming language to write the UNIX operating system.Main features of CWhy Learn C?C is considered mother of all programmin
6 min read
Data Types in C Each variable in C has an associated data type. It specifies the type of data that the variable can store like integer, character, floating, double, etc.Example:C++int number;The above statement declares a variable with name number that can store integer values.C is a statically type language where
5 min read
Dynamic Memory Allocation in C using malloc(), calloc(), free() and realloc() In C, a variable defined in a function is stored in the stack memory. The requirement of this memory is that it needs to know the size of the data to memory at compile time (before the program runs). Also, once defined, we can neither change the size nor completely delete the memory.To resolve this,
9 min read
C Arrays An array in C is a fixed-size collection of similar data items.Items are stored in contiguous memory locations. Can be used to store the collection of primitive data types such as int, char, float, etc., as well as derived and user-defined data types such as pointers, structures, etc.C// A simple C
7 min read
C Programs To learn anything effectively, practicing and solving problems is essential. To help you master C programming, we have compiled over 100 C programming examples across various categories, including basic C programs, Fibonacci series, strings, arrays, base conversions, pattern printing, pointers, and
8 min read
C Pointers A pointer is a variable that stores the memory address of another variable. Instead of holding a direct value, it holds the address where the value is stored in memory. It is the backbone of low-level memory manipulation in C. Accessing the pointer directly will just give us the address that is stor
9 min read
Operators in C Operators are the basic components of C programming. They are symbols that represent some kind of operation, such as mathematical, relational, bitwise, conditional, or logical computations, which are to be performed on values or variables. The values and variables used with operators are called oper
11 min read
C Programming Interview Questions (2025) At Bell Labs, Dennis Ritchie developed the C programming language between 1971 and 1973. C is a mid-level structured-oriented programming and general-purpose programming. It is one of the oldest and most popular programming languages. There are many applications in which C programming language is us
15+ min read
Bitwise Operators in C In C, bitwise operators are used to perform operations directly on the binary representations of numbers. These operators work by manipulating individual bits (0s and 1s) in a number.The following 6 operators are bitwise operators (also known as bit operators as they work at the bit-level). They are
6 min read