How to Compile and Run a C Program in VS Code, Terminal and Turbo C++
To run a C program, install GCC, save your code as a .c file, then compile it with gcc program.c -o program in a terminal. On Linux or Mac run ./program; on Windows run program.exe. Setup takes under two minutes.
- Install GCC (or MinGW on Windows)
- Write your code and save it as hello.c
- Open a terminal in the same folder
- Run gcc hello.c -o hello to compile
- Execute with ./hello (Linux/Mac) or hello.exe (Windows)
- GCC is the go-to compiler for beginners on Linux and Mac. Windows users need MinGW to get GCC working.
- VS Code with the C/C++ extension gives you syntax highlighting, error squiggles and a built-in terminal in one window.
- Turbo C++ still appears in some Indian university syllabi but it is a legacy tool from the 1990s. Do not use it for new projects.
- Most beginner errors, like “gcc is not recognised” or a missing semicolon, have one-line fixes.
- A do-while loop is one of the first C constructs you should practise compiling and running yourself.
How to Compile and Run a C Program from the Terminal
The terminal is the fastest way to understand what is actually happening when you run a C program. No buttons, no menus. Just you, the compiler and the output.
Step 1: Install GCC
On Ubuntu or Debian Linux, open a terminal and run sudo apt install gcc. GCC ships with most Linux distros, so you may already have it. Check with gcc –version.
On macOS, Apple’s Command Line Tools include clang aliased as GCC. Run xcode-select –install and you are done. Confirm with gcc –version in Terminal.
On Windows, download MinGW from mingw-w64.org, run the installer, and add the MinGW bin folder to your System PATH. The typical path is C:\MinGW\bin. After that, open Command Prompt and type gcc –version to confirm it is recognised.
Step 2: Write and Save Your C File
Open any text editor, write your code, and save it as hello.c. Here is the simplest valid C program:
#include <stdio.h>
int main() {
printf(“Hello, World!\n”);
return 0;
}
Save it to a folder you can find easily. Indian students often use a folder like C:\Users\YourName\cfiles\ on Windows or ~/cfiles/ on Linux. Students at IITs, NITs and affiliated colleges under boards like CBSE will find this folder structure matches most lab manual instructions.
Step 3: Compile and Run Your C Program on Windows, Linux and Mac
Open your terminal, navigate to the folder with cd cfiles, then compile:
gcc hello.c -o hello
This tells GCC to compile hello.c and output an executable named hello. Now run it:
- Linux / Mac: ./hello
- Windows: hello.exe
You should see Hello, World! printed in the terminal. That is it. You have just executed a C program. If you are on a low-spec machine or a shared college computer, online compilers like OnlineGDB or Replit let you compile and run a C program entirely in the browser with no local installation needed.
Fixing “gcc is not recognised”
This error on Windows means MinGW’s bin folder is not in your PATH. Go to System Properties, click Environment Variables, find Path under System variables, click Edit, and add the path to your MinGW bin folder. Restart Command Prompt and run gcc –version again.
Fixing a Missing Semicolon Error
GCC will print something like error: expected ‘;’ before ‘}’. Read the line number it gives you, go to that line in your file, and add the semicolon. C is strict: every statement must end with one. According to JetBrains’ Developer Ecosystem Survey 2023, 57% of developers reported syntax and compilation errors as the most common stumbling block in their first month with a compiled language.
How to Run a C Program in Visual Studio Code
VS Code is the most popular code editor in the world. Stack Overflow’s Developer Survey 2024 found that 73.6% of professional developers use VS Code as their primary editor. Setting it up to compile and run a C program takes about ten minutes.
Install the C/C++ Extension
Open VS Code, press Ctrl+Shift+X to open the Extensions panel, search for C/C++ and install the extension published by Microsoft. This adds IntelliSense, error highlighting and debugging support. You still need GCC or MinGW installed on your system because VS Code is an editor, not a compiler.
Configure tasks.json
Press Ctrl+Shift+P, type Tasks: Configure Default Build Task, and select C/C++: gcc build active file. VS Code creates a .vscode/tasks.json file in your workspace. The key line in that file looks like this:
“command”: “/usr/bin/gcc” (Linux/Mac) or “command”: “C:/MinGW/bin/gcc.exe” (Windows)
Once saved, press Ctrl+Shift+B to build your active .c file. The compiled output appears in the same folder. Then open VS Code’s integrated terminal with Ctrl+` and run ./hello or hello.exe.
Run Directly with the Code Runner Extension
Install the Code Runner extension by Jun Han from the Extensions panel. Now you can right-click any .c file and choose Run Code. It compiles and runs in one step using the terminal at the bottom of the screen. This is the fastest workflow for beginners who want to execute a C program output without touching the command line manually every time.
If you are serious about structured learning, 3.0 University’s online certification courses cover programming fundamentals alongside cybersecurity and AI, giving you a practical skill stack that employers actually look for.
How to Run a C Program in Turbo C++ and Write Your First Loop
Turbo C++: Still on Indian Syllabi, But Know Its Limits
Turbo C++ was developed by Borland in the early 1990s. It is a 16-bit DOS-era compiler and IDE that has not seen active development in decades. The reason it still appears in some Indian university practicals, especially at affiliated colleges under boards like CBSE and several state universities, is purely historical. Many lab manuals were written for it and simply have not been updated.
If your college specifically asks for Turbo C++, use DOSBox to run it on a modern 64-bit Windows machine. Download Turbo C++ from a trusted archive, set up DOSBox, mount the directory, and launch TC.EXE. Inside the IDE, press Alt+F9 to compile and Ctrl+F9 to run. For anything beyond a classroom submission, switch to GCC. Competitive programming platforms popular in India, including CodeChef and HackerRank, use GCC as their default C compiler, so learning GCC now prepares you for real contests.
A do-while Loop Example in C
The do-while loop is guaranteed to execute its body at least once, unlike a regular while loop. Here is a practical example that prints a multiplication table, which also shows you how to draw a table in C programming using formatted output:
#include <stdio.h>
int main() {
int i = 1;
int num = 5;
printf(“Table of %d\n”, num);
printf(“%-5s %-5s %-5s\n”, “N”, “x”, “Result”);
do {
printf(“%-5d x %-3d = %d\n”, num, i, num * i);
i++;
} while (i <= 10);
return 0;
}
The %-5d format specifier left-aligns numbers in a field of five characters, creating a clean column layout in the terminal. This is the simplest way to draw a table in C programming without any graphics library. Compile it with gcc table.c -o table and run it. You will see a neatly formatted multiplication table for 5.
Practising small programs like this daily is exactly what the REACH learner community at 3.0 University encourages. Consistent hands-on practice beats binge-reading theory every time.
Compiler Comparison for Beginners
| Compiler / Tool | Platform | Best For | Still Recommended? | C Standard Support |
|---|---|---|---|---|
| GCC (via MinGW) | Windows | All beginners on Windows | Yes | C89, C99, C11, C17 |
| GCC (native) | Linux | All beginners on Linux | Yes | C89, C99, C11, C17 |
| Clang (Apple) | macOS | Mac users, fast error messages | Yes | C89, C99, C11, C17 |
| Turbo C++ 3.0 | DOS / DOSBox | Legacy college practicals only | No | C89 only (partial) |
| VS Code + GCC | Windows / Linux / Mac | Beginners wanting an IDE feel | Yes | Depends on GCC version |
GCC version 13, released in April 2023, brought improved diagnostics and partial C23 support, according to the official GCC release notes. For beginners, any GCC version from 9 onwards handles everything you will write in your first year of C comfortably.
The rise of AI-assisted coding tools does not make knowing how to run a C program less important. If anything, understanding compilation errors helps you prompt AI tools more effectively. Check out 3.0 University’s take on the AI job market and skills to see why foundational programming knowledge still matters in 2025 and beyond.
According to TIOBE’s Programming Community Index for early 2025, C holds the number one position among all programming languages by usage, ahead of Python and C++. That is not a reason to learn it out of nostalgia. It is a sign that systems programming, embedded development and competitive programming keep it in active demand.
If you want to pair C fundamentals with real-world tools, the GitHub Education program gives students free access to GitHub Codespaces, where you can compile and run C programs entirely in the browser without installing anything locally.
The bootcamp training programs at 3.0 University take this further with structured lab environments, mentor support and project-based assessments that go well beyond hello-world exercises.
For deeper reading on programming tools, career paths and industry trends, the 3.0 University blog publishes practical guides updated regularly by practitioners, not just academics.
Your concrete next steps this week: install GCC on your machine, compile and run the do-while loop example above, then try modifying it to print the table for any number the user enters using scanf. That single exercise teaches you compilation, loops, formatted output and user input in one go.
Frequently Asked Questions
How do I run a C program?
To run a C program, install GCC, write your code in a .c file, open a terminal in the same folder, and run gcc program.c -o program. Then execute it with ./program on Linux or Mac, or program.exe on Windows. The whole process takes under two minutes once your compiler is installed and your PATH is set correctly.
How do I compile and run C in VS Code?
Install VS Code, then install the Microsoft C/C++ extension and the Code Runner extension. Make sure GCC or MinGW is installed on your system. Open your .c file, press Ctrl+Shift+B to build, then run the output in VS Code’s integrated terminal. Alternatively, right-click the file and choose Run Code for a one-click workflow.
How do I run a C program in Turbo C++?
Open Turbo C++ (via DOSBox on modern Windows), load your .c file using File, Open, press Alt+F9 to compile, and Ctrl+F9 to run. Turbo C++ is a legacy 16-bit compiler still used in some Indian college practicals. For anything outside a mandated syllabus, use GCC instead. It supports modern C standards that Turbo C++ simply cannot handle.
How do I write a do-while loop in C?
A do-while loop runs its body first, then checks the condition. The syntax is: do { statements; } while (condition);. It is useful when you need the loop body to execute at least once, such as showing a menu before checking the user’s input. Compile a simple example with GCC and run it to see the difference from a regular while loop.
What compiler should a beginner use for C?
Use GCC. It is free, open-source, available on every major OS, and supports all modern C standards up to C17. On Windows, install it through MinGW. On Linux it is one command away. Pair it with VS Code for a comfortable editing experience. Avoid Turbo C++ unless your institution specifically requires it for a practical exam.
Ready to go further than hello-world? Explore 3.0 University’s online certification courses in Cybersecurity, Ethical Hacking, Artificial Intelligence, Blockchain and Web3. Every course is built around hands-on labs and real-world projects, so you graduate with skills you can actually demonstrate to an employer, not just a certificate to frame on the wall.
Last updated: June 2025. Reviewed by the 3University editorial team.


