C-Program
Setting Up the Environment
Last Updated on: 3rd Jul 2025 03:44:45 AM
Before writing C programs, you need to set up your computer with a C compiler. A compiler converts your code into machine language so your computer can run it.
Installing a C Compiler :
There are several C compilers available. Two of the most commonly used are:
Option 1: Dev-C++ (Recommended for Beginners)
Dev-C++ 5.11 is a lightweight and user-friendly IDE (Integrated Development Environment) that includes a compiler.
=> Steps to Install:
-
Download Dev-C++ 5.11 from a trusted source (like SourceForge).
-
Run the
.exe
setup file. -
Follow the installation steps (click "Next" until it's complete).
-
Open Dev-C++ after installation.
Note: Dev-C++ uses the MinGW (GCC) compiler internally, which is widely used and supports modern C standards.
Option 2: Turbo C++ (Old But Popular in Schools)
Turbo C++ is a DOS-based compiler still used in some educational institutions.
=> Steps to Install:
-
Download Turbo C++ (ideally a Windows-compatible version or use DOSBox).
-
Install and run the setup.
-
Use
Alt + F9
to compile andCtrl + F9
to run a program.
Note: Turbo C++ is outdated and does not support many modern features. It is not recommended for professional use.
Writing and Running Your First C Program
Once the compiler is installed, follow these steps to write and execute your first program:
Step-by-Step (Using Dev-C++):
-
Open Dev-C++
-
Click on File → New → Source File
-
Type the following code:
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
-
Save the file with a
.c
extension, e.g.,hello.c
-
Click on Execute → Compile & Run or press
F11
Explanation of the Program:
#include <stdio.h> // Includes standard input-output library
int main() { // Starting point of the program
printf("Hello, World!"); // Prints text to screen
return 0; // Ends the program
}
-
#include <stdio.h>
– This allows us to use theprintf
function. -
int main()
– The main function where the execution begins. -
printf()
– Prints the message to the output screen. -
return 0;
– Tells the operating system that the program ended successfully.
Congrats! You have successfully written and executed your first C program.