Install the C Compiler
The C compiler we use for Windows development is MinGW-W64 GCC, with two common installation approaches, the offline method below is recommended for beginners:
- Direct download from the official SourceForge repository: https://sourceforge.net/projects/mingw-w64/
- Use a preconfigured offline installation package. After downloading the package, extract it to your preferred installation location. Open the extracted folder, navigate into the
binsubdirectory, then copy the full path of this directory from the File Explorer address bar.
Add System Environment Variable
To make GCC accessible from any working directory in the system, add the copied bin path to your system PATH environment variable:
- Right-click This PC on your desktop → select Properties → open Advanced System Settings → switch to the Advanced tab → click Environment Variables.
- Locate the
Pathvariable under System Variables, click Edit, then click New and paste the copiedbindirectory path. Click OK sequentially to save all changes (do not skip confirmation steps, otherwise your changes will not take effect).
To verify the configuration, press Win + R, type cmd to open Command Prompt, then run the command gcc -v (note the space between gcc and -v). If GCC version information is printed in the terminal, the environment variable is configured correctly.
Install Visual Studio Code
Download the VSCode installer from the official website: https://code.visualstudio.com/. Run the installer after the download completes, make sure to check the options to create a desktop shortcut and add VSCode to your system PATH, then finish the installation process.
Configure VSCode Extensions and Settings
Open VSCode after installation, go to the Extensions panel on the left sidebar, install the following two extensions:
- C/C++ (official Microsoft extension for C/C++ development)
- Code Runner
After installing the extensions, open the Settings panel: you can navigate via File → Preferences → Settings or use the keyboard shortcut Ctrl + ,. Scroll to Extensions → Run Code Configuration, check the following three options:
Run in TerminalSave All Files Before RunSave File Before RunClose the settings panel after you finish updating these options.
Create and Run Your First C Program
- Create a new empty folder on your local system (follow good naming habits: use English names with no spaces, for example
CProjectsinstead of names with Chinese or spaces). - In VSCode, go to File → Open Folder, select the folder you just created to open it as your current workspace.
- Right-click the empty area in VSCode's file explorer panel, select New File, name the file
hello.c.
Add the following code to the new file:
#include <stdio.h>
int main(void)
{
printf("Hello VSCode C development environment!\n");
return 0;
}
Next configure the build task: go to Terminal → Configure Default Build Task, select the option C/C++: gcc.exe build active file. VSCode will automatically generate a tasks.json configuration file, you can close this file without any modifications.
Go back to your hello.c file, right-click and select Run Code to execute the program. You will see the output in the integrated terminal, which confirms your basic C environment is working correctly.
Set Up C Debugging in VSCode
Debugging is an essential tool for tracing code logic and locating bugs, follow these steps to enable full debugging support:
- Go to Run → Start Debugging, when prompted to select a debugger, choose
C++ (GDB/LLDB), then selectgcc.exe - build and debug active file. VSCode will automatically generate all required debug configuration files.
Set Breakpoints
To test the debugging workflow, use the following sample addition program:
#include <stdio.h>
int main(void) {
int num1, num2, total;
printf("Enter two integers:\n");
scanf("%d %d", &num1, &num2);
total = num1 + num2;
printf("%d + %d = %d\n", num1, num2, total);
return 0;
}
To add a breakpoint, click the gutter (the empty vertical bar to the left of the line numbers) next to the line where you want execution to pause. A red solid dot will appear to confirm the breakpoint is set correctly.
Start Debugging
You can press the F5 shortcut to start debugging directly, or select Run → Start Debugging from the top menu bar. Once debugging starts, the program will run automatically until it hits you're set breakpoint, then pause to let you inspect the program state.
Use the debug control bar at the top of the editor to navigate through your code: hovering your mouse over each button will display its function description. Click the Step Over button (the first arrow button in the control bar) to move execution to the next line. When prompted in the terminal, enter two integers such as 6 11, then continue stepping through the code. You can inspect the current value of all variables in the debug sidebar, and the final calculation result will be printed to the terminal after execution completes.
Useful Recommended Extensions
Chinese (Simplified) Language Pack
If you prefer a localized Chinese interface, search for Chinese in the Extensions panel, install the official Simplified Chinese language pack, and restart VSCode to apply the change.
Rainbow Brackets
This extension color-codes matching pairs of parentheses and brackets, making it much easier to track nested code blocks and avoid syntax errors caused by mismatched brackets.