π§ Setup C Language in VS Code (Step-by-Step Guide)
π What is C Language?
C is a powerful and fast programming language. But it needs to be compiled before running,
unlike Python or JavaScript.
A compiler converts your C code into a machine-readable format (like .exe) so the computer can
understand it.
π οΈ Tools You Need to Install
- Visual Studio Code (VS Code) β For writing code
- MinGW Compiler (GCC) β For compiling and running C programs
- C/C++ Extension in VS Code β For IntelliSense and debugging
π₯ Step 1: Install MinGW (C Compiler)
- Go to MinGW-w64 Download
(SourceForge)
- Download and open
- Click install
- Click Continue
- Right click and select following :
- mingw-develope-toolkit
- mingw32-base
- mingw32-gcc-g++
- mingw32-gcc-objc
- msys-base
- Go to installation (top-left corner of the window) and click "apply changes"
- Close all windows
- Go to "My PC" and open your "C Drive"
- Open MinGW and open bin folder
- Copy the path from above
- Open system environment variables and paste that path creating as new path
- open cmd and check version : g++ --version
π Step 2: Add GCC to System PATH
Without this step, the terminal wonβt recognize the gcc command.
- Search for Environment Variables in Windows Search
- Click Edit the system environment variables
- Click Environment Variables...
- Under System Variables, select Path β Click Edit
- Click New and paste:
C:\Program Files\mingw-w64\mingw64\bin
- Click OK on all windows and restart your computer
π§ͺ Step 3: Check if GCC Works
Open your Command Prompt or VS Code Terminal and run:
gcc --version
If it shows the version, youβre ready to go!
π» Step 4: Setup VS Code
- Open VS Code
- Install the extension: C/C++ by Microsoft
- Create a folder, then a file called
hello.c
- Write this basic program:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
πββοΈ Step 5: Compile and Run
- Open Terminal in VS Code (
Ctrl + `)
- Type:
gcc hello.c -o hello
- Run it:
./hello
If you're on Windows:
hello.exe
π‘ gcc hello.c -o hello means:
π Compile hello.c and make an output file named hello.exe
π Common Errors and Fixes
- 'gcc' is not recognized: You forgot to install MinGW or add to PATH
- Permission denied: Use correct file names and paths
- Output not showing: Make sure you compile before running
π You're Done!
Congratulations! You now have C running on your computer like a pro coder! π