back to course
Lesson 02 / 395%· free preview
Getting Started2/5
C Get Started
Get started coding in C with VS Code and MinGW for a seamless beginner experience.
Installing VS Code
Visual Studio Code (VS Code) is a popular and lightweight editor for coding. Follow these steps to install it:
- Download and install VS Code from the official website or trusted sources.
- To open VS Code quickly: Press the Windows key, type "VS Code" and hit Enter.
Installing Compiler (MinGW) – Supports C & C++
You need a compiler to translate your code into a working program. MinGW provides the tools to compile both C and C++ code.
Steps to Install MinGW
-
Download MinGW
- Open a web browser and search for "MinGW download." Download the installer (mingw-get-setup.exe).
-
Run Installer
- Open your downloads (Ctrl + J), then double-click the installer.
- Click Install, set the location to
C:\MinGW.
-
Select Packages
- Select
mingw32-baseandmingw32-gcc-g++. - Right-click each and select 'Mark for Installation.'
- Select
-
Apply Changes
- Go to 'Installation' > 'Apply Changes' and wait for installation to finish.
-
Set PATH Environment Variable
- Press Windows + S and search for "Environment Variables." Edit environment variables, select Path, click Edit, then New. Add:
C:\MinGW\bin
- Press Windows + S and search for "Environment Variables." Edit environment variables, select Path, click Edit, then New. Add:
-
Verify Installation
- Open the command prompt (Windows + R, type
cmd, press Enter). - Run:
gcc --versiong++ --version- If both display version information, your installation is complete.
- Open the command prompt (Windows + R, type
Important
| Compiler | Language |
|---|---|
| gcc | C |
| g++ | C++ |
Installing Extensions in VS Code
To enhance coding features in VS Code, install:
- C/C++ Extension (from Microsoft)
- Code Runner (for one-click code execution)
Open Extensions panel using Ctrl + Shift + X.
Creating and Saving Files
- Open a project folder: Ctrl + K, then Ctrl + O.
- Create a new file: Ctrl + N.
- Save a file: Ctrl + S.
- Example file names:
main.c(for C),main.cpp(for C++).
Writing Your First Code
Write your program in main.c:
c#include <stdio.h> int main() { printf("Hello from C"); return 0; }
Output
textHello from C
(C++ version for comparison)
c#include <iostream> using namespace std; int main() { cout << "Hello from C++"; return 0; }
Compiling Code (Manual Method)
- Open Terminal in VS Code: Ctrl + `
- Compile for C:
gcc main.c -o main - Compile for C++:
g++ main.cpp -o main
Running the Program
- Enter
./mainin the terminal to execute the program.
Using Code Runner (One-Click Run)
- Run your code: Ctrl + Alt + N
- Stop execution: Ctrl + Alt + M
Output Settings
- To configure the default output panel, press Ctrl + , (open settings)
- Search: 'Code Runner: Run In Terminal'
- Turn OFF for simple output in the Output panel.
- To enable interactive input in the terminal, turn ON 'Run In Terminal.'
- To view output, use Ctrl + Shift + U and select 'Code Runner'.
Output vs Terminal Usage
| Mode | Use |
|---|---|
| OUTPUT | Simple programs |
| TERMINAL | Input programs |
Pro Setup (Auto Compile)
Advanced users can set up auto-compilation:
- Open Command Palette: Ctrl + Shift + P
- Type: 'Tasks: Configure Task'
- Select: 'C/C++: g++.exe build active file'
- To build: Ctrl + Shift + B
Key Takeaways
- Setting up VS Code and MinGW provides a complete environment for C development.
- Configuring the PATH variable ensures the compiler runs from any terminal window.
- VS Code extensions like C/C++ and Code Runner simplify editing and running code.
- Manual compiling reinforces understanding of the build process.
- Output modes in VS Code help tailor the experience for different program requirements.
Interview Questions
Practice Questions
- Install VS Code and MinGW, then verify installation by compiling a sample program.
- Create a new C file named
hello.cand print "Hello, World!". - Compile
hello.cusing the terminal and run the executable. - Set up VS Code extensions for C programming and test one-click run.
- Configure Code Runner’s output to use the Terminal for input-enabled programs.
Pro Tips
- Always verify your compiler installation with version commands before writing code.
- Use shortcuts for faster navigation in VS Code.
- Save files with '.c' for C or '.cpp' for C++ to ensure proper syntax detection.
- For input and output programs, use the Terminal mode in Code Runner.
- Configure build tasks in VS Code for automatic or one-touch compilation.
- Regularly update extensions for improved performance and features.
AI-powered recap
Quick recap quiz?
We'll generate 5 MCQs from this lesson and check your understanding instantly. Takes ~30 seconds.
# program
Program
C
#include <stdio.h>
int main(void) {
printf("Hello from C\n");
return 0;
}Ready to move on?
// example library
Practice C Get Started with runnable code
Browse 360 runnable examples · across 36 chapters · short, copy-paste-friendly · grouped by topic
// suggested companion course
Data Structures with C
Comfortable with C? Level up — arrays · linked lists · stacks · queues · trees · graphs · sorting algorithms.
// deep-dive
Go deeper — hand-picked articles
Long-form guides, shortcuts, and mental models that won't fit in a single lesson.
// feedback.matters()
Did this lesson help you?
100% found this helpful · 1 vote
