How to Write, Compile and Run a C Program (Step by Step)
To run a C program, save your code as a .c file, compile it with GCC using gcc hello.c -o hello, then execute it with ./hello on Linux/Mac or hello.exe on Windows. The whole process takes under five minutes once your compiler is installed.
- Key Takeaway 1: GCC (via MinGW on Windows) is the go-to compiler for beginners. It’s free, widely supported, and used in most Indian university syllabi.
- Key Takeaway 2: You only need three things: a text editor, a compiler, and a terminal. VS Code bundles all three cleanly.
- Key Takeaway 3: The compile command and the run command are two separate steps. Mixing them up is the most common beginner mistake.
- Key Takeaway 4: C is still actively used in embedded systems, operating systems, and competitive programming, so learning it has real career value in 2026.
- Key Takeaway 5: Most “gcc not recognised” errors on Windows are a PATH configuration problem, not a broken installation.
Set Up a Compiler and Editor Before You Write a Single Line
You cannot run a C program without a compiler. A compiler translates your human-readable C code into machine code the CPU can actually execute. That is what a compiler in C programming does at its core: it reads your .c file and produces a binary executable.
GCC (GNU Compiler Collection) is the industry standard. It is what IIT and NIT lab manuals reference, it is what most open-source projects use, and it is free. According to the Stack Overflow Developer Survey 2024, C remains among the top 15 most-used programming languages globally, with particular strength in systems programming and competitive coding communities.
Installing GCC on Windows with MinGW
On Windows, GCC does not come natively. You install it through MinGW (Minimalist GNU for Windows), which packages GCC for Windows environments. Download the MinGW installer from mingw-w64.org, run it, and select the gcc and g++ packages.
After installation, you must add MinGW’s bin folder to your Windows PATH. Open System Properties, go to Environment Variables, find the Path variable under System variables, click Edit, and add the path to your MinGW bin folder (usually C:\MinGW\bin). Restart your terminal after doing this.
Installing GCC on Linux and Mac
On Ubuntu or any Debian-based Linux, open a terminal and run sudo apt install gcc. On macOS, run xcode-select –install to get Apple’s Clang compiler, which is GCC-compatible for all beginner and intermediate use cases.
Verify the installation on any OS by running gcc –version in your terminal. If you see a version number, you are ready to write and run a C program.
What Is C Programming Used For Today?
C is not a legacy language sitting in a museum. It powers the Linux kernel, embedded firmware in IoT devices, real-time systems in automotive and aerospace, and the internals of databases like PostgreSQL. According to the TIOBE Index (June 2025), C holds a top-3 position in programming language popularity, ahead of JavaScript in several consecutive months.
In India specifically, C is a mandatory subject in B.Tech and BCA programs across AICTE-affiliated colleges. It is also a core language in GATE CS preparation and competitive programming on platforms like Codeforces. If you are thinking about career paths after 12th grade in 2026, a solid foundation in C gives you a head start in almost every engineering stream.
| Platform | Compiler/Tool | Best For | Cost |
|---|---|---|---|
| Windows | MinGW (GCC) | Beginners, college labs | Free |
| Linux (Ubuntu) | GCC (apt package) | Developers, open-source work | Free |
| macOS | Clang (Xcode CLI tools) | Mac users, GCC-compatible | Free |
| Online (any OS) | OnlineGDB, Replit | Quick testing, no install needed | Free (basic) |
| Windows/Linux/Mac | VS Code + C/C++ Extension | Full projects, debugging | Free |
How to Run a C Program: Command Prompt and Terminal Steps
This is the core skill. Everything else, VS Code, IDEs, build systems, sits on top of this basic workflow. Once you understand how to run a C program from the command line, every other tool makes sense immediately.
Step 1: Write Your First C Program
Open any text editor (Notepad on Windows, gedit or nano on Linux) and type the following:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
Save the file as hello.c. The .c extension tells the compiler this is a C source file. Save it somewhere easy to find, like your Desktop or a folder called C_Programs.
Step 2: Compile the Program with GCC
Open Command Prompt (Windows) or Terminal (Linux/Mac). Navigate to the folder where you saved hello.c using the cd command. For example: cd Desktop\C_Programs on Windows, or cd ~/Desktop/C_Programs on Linux/Mac.
Now compile it:
gcc hello.c -o hello
This tells GCC to compile hello.c and output an executable named hello. If there are no errors, GCC runs silently and creates the executable in the same folder.
Step 3: Run the Compiled Program
On Linux or Mac, type: ./hello
On Windows, type: hello.exe
You will see Hello, World! printed in the terminal. That is how to run a C program successfully from scratch.
How to Run a C Program in CMD: Troubleshooting Common Errors
If things go wrong, here are the most common problems and their fixes:
- “gcc is not recognised as an internal or external command”: MinGW is not in your PATH. Go back to the PATH setup step and restart your terminal.
- “No such file or directory”: You are not in the right folder. Use cd to navigate to where
hello.cis saved, then compile again. - Permission denied (Linux/Mac): Run chmod +x hello to give the file execute permission, then try ./hello again.
- Compilation errors (syntax errors): GCC will print the line number where the error is. Check for missing semicolons, mismatched brackets, or typos in function names.
- Program compiles but shows nothing: Make sure your
printfstatement ends with\nand that you have included#include <stdio.h>at the top.
According to the JetBrains Developer Ecosystem Survey 2023, over 55% of C and C++ developers use a command-line compiler as part of their primary workflow, confirming that this terminal-based skill is genuinely practical and not just an academic exercise.
How to Run a C Program in VS Code
VS Code is the editor of choice for most Indian engineering students who want something between a raw text editor and a heavy IDE like Code::Blocks. It is lightweight, free, and has excellent extension support. The Stack Overflow Developer Survey 2024 ranked VS Code as the most popular development environment for the seventh consecutive year, used by over 73% of respondents globally, including a large share of Indian developers.
Install the C/C++ Extension
Open VS Code, click the Extensions icon on the left sidebar (or press Ctrl+Shift+X), search for C/C++, and install the extension published by Microsoft. This extension adds IntelliSense (auto-complete), syntax highlighting, and debugging support for both C and C++ files.
You still need GCC installed separately. VS Code does not bundle a compiler. It uses the GCC you installed via MinGW (Windows) or apt/Xcode (Linux/Mac).
Configure and Run Your Program in VS Code
Open your hello.c file in VS Code. Open the integrated terminal with Ctrl+` and type the GCC command manually:
gcc hello.c -o hello
Then run ./hello or hello.exe directly in that terminal. For a more automated setup, go to Terminal > Configure Default Build Task, select C/C++: gcc build active file, and VS Code will create a tasks.json file. After that, pressing Ctrl+Shift+B compiles the current file automatically.
How to Run a C++ Program in VS Code
The process for C++ is almost identical. Write your code in a .cpp file instead of .c, and use g++ instead of gcc to compile:
g++ hello.cpp -o hello
Then run it the same way: ./hello on Linux/Mac or hello.exe on Windows. The VS Code C/C++ extension handles both languages with the same setup. If you are exploring programming languages for blockchain development, C++ is particularly relevant since many blockchain protocols are written in it.
Which App Is Used for C Programming?
For beginners, the top choices are VS Code (with the C/C++ extension), Code::Blocks, and Dev-C++. For quick practice without installation, OnlineGDB and Replit work well. In Indian college labs, Turbo C is still sometimes used, but it is outdated and not recommended for anything beyond legacy coursework. GCC-based setups are the professional standard and worth learning from day one.
If you are a student who qualifies for GitHub’s student developer pack, you get access to several premium dev tools for free. The GitHub Education Program is worth exploring alongside your C learning journey.
Working on projects that go beyond basic programs? Check out the cybersecurity projects for students on 3.0 University’s learning hub. Many of them involve C-level systems thinking and are a strong portfolio addition for Indian engineering students targeting product companies or government tech roles.
Want to explore more programming topics and tools? The 3.0 University learning hub covers everything from foundational programming to advanced cybersecurity and AI.
C programming is a skill that compounds. Every hour you spend understanding pointers, memory management, and compilation directly makes you better at understanding how operating systems, networks, and security tools actually work under the hood. If you want to turn that foundation into a career-ready skill set, explore the online certification courses at 3.0 University covering Cybersecurity, Ethical Hacking, AI, Blockchain, and Web3.
Frequently Asked Questions
How do I run a C program in Command Prompt?
Open Command Prompt, navigate to your .c file’s folder using cd, compile with gcc hello.c -o hello, then run with hello.exe. If GCC is not recognised, MinGW is not in your Windows PATH. Add the MinGW bin folder to your PATH environment variable and restart the terminal. This is the standard way to run a C program in CMD on Windows.
How do I run a C program in VS Code?
Install VS Code and the Microsoft C/C++ extension, then install GCC via MinGW (Windows) or apt/Xcode (Linux/Mac). Open your .c file, launch the integrated terminal with Ctrl+`, and run gcc hello.c -o hello followed by ./hello or hello.exe. You can also configure a build task to automate the compile step with Ctrl+Shift+B.
Which compiler should beginners install for C?
GCC is the best choice for beginners. On Windows, install it via MinGW from mingw-w64.org. On Linux, use sudo apt install gcc. On macOS, run xcode-select –install to get Clang, which is fully compatible. All three are free and widely used in Indian university courses and competitive programming.
How do I run a C program on Linux or Mac?
Open a terminal, navigate to your file’s directory, compile with gcc hello.c -o hello, then run with ./hello. On Mac, use Clang via Xcode command-line tools. If you get a permission denied error on Linux, run chmod +x hello first. The workflow to run a C program is identical on both platforms.
What is C programming used for today?
C is used in operating system kernels (Linux, Windows internals), embedded systems, IoT firmware, real-time software, database engines, and competitive programming. It is a core subject in B.Tech and BCA programs across India’s AICTE-affiliated colleges. The TIOBE Index consistently ranks C in the top 3 most-used programming languages globally as of 2025.
Last updated: August 2026. Reviewed by the 3University editorial team.


