Turning Learners Into Developers
Codekilla
CODEKILLA
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
  1. Download MinGW

    • Open a web browser and search for "MinGW download." Download the installer (mingw-get-setup.exe).
  2. Run Installer

    • Open your downloads (Ctrl + J), then double-click the installer.
    • Click Install, set the location to C:\MinGW.
  3. Select Packages

    • Select mingw32-base and mingw32-gcc-g++.
    • Right-click each and select 'Mark for Installation.'
  4. Apply Changes

    • Go to 'Installation' > 'Apply Changes' and wait for installation to finish.
  5. 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
  6. Verify Installation

    • Open the command prompt (Windows + R, type cmd, press Enter).
    • Run:
      • gcc --version
      • g++ --version
      • If both display version information, your installation is complete.
Important
CompilerLanguage
gccC
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
text
Hello 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 ./main in 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
ModeUse
OUTPUTSimple programs
TERMINALInput 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
  1. Setting up VS Code and MinGW provides a complete environment for C development.
  2. Configuring the PATH variable ensures the compiler runs from any terminal window.
  3. VS Code extensions like C/C++ and Code Runner simplify editing and running code.
  4. Manual compiling reinforces understanding of the build process.
  5. Output modes in VS Code help tailor the experience for different program requirements.
Interview Questions

Practice Questions
  1. Install VS Code and MinGW, then verify installation by compiling a sample program.
  2. Create a new C file named hello.c and print "Hello, World!".
  3. Compile hello.c using the terminal and run the executable.
  4. Set up VS Code extensions for C programming and test one-click run.
  5. Configure Code Runner’s output to use the Terminal for input-enabled programs.
Pro Tips
  1. Always verify your compiler installation with version commands before writing code.
  2. Use shortcuts for faster navigation in VS Code.
  3. Save files with '.c' for C or '.cpp' for C++ to ensure proper syntax detection.
  4. For input and output programs, use the Terminal mode in Code Runner.
  5. Configure build tasks in VS Code for automatic or one-touch compilation.
  6. 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
Open chapter
// suggested companion course
Data Structures with C
Comfortable with C? Level up — arrays · linked lists · stacks · queues · trees · graphs · sorting algorithms.
Open course
// deep-dive
Go deeper — hand-picked articles
Long-form guides, shortcuts, and mental models that won't fit in a single lesson.
Open Blog
// feedback.matters()
Did this lesson help you?
100% found this helpful · 1 vote