DEV Community

Cover image for Run C Code in Visual Studio Code
Haytham Mostafa
Haytham Mostafa

Posted on • Updated on

Run C Code in Visual Studio Code

Why the C Programming Language Still Used?

C is a lot faster when compared to Python as it is designed to be a low-level language whereas in Python, the compiler first has to interpret the syntax before running the program. C++, built on C, is faster because of its object-oriented nature and is the most used language in competitive programming.

C is very close to hardware and can directly interact with it(managing memory). The C code you write is converted into assembly language by the compiler and then run as instructions on the hardware. This is helpful as you get to understand the working of compilers.

C is used in embedded hardware that forms a part of ovens, TV remotes, vending machines, IoT, etc. IoT has given rise to the idea of smart cities which I have explained in an earlier post.

C exists everywhere in the modern world. A lot of applications, including Microsoft Windows, run on C. Even Python, one of the most popular languages, was built on C. Modern applications add new features implemented using high-level languages, but a lot of their existing functionalities use C, such as:

Microsoft Windows
Microsoft’s Windows kernel is developed mostly in C, with some parts in assembly language. For decades, the world’s most used operating system, with about 90 percent of the market share, has been powered by a kernel written in C.

Linux is also written mostly in C, with some parts in assembly. About 97 percent of the world’s 500 most powerful supercomputers run the Linux kernel. It is also used in many personal computers.

Mac computers are also powered by C, since the OS X kernel is written mostly in C. Every program and driver in a Mac, as in Windows and Linux computers, is running on a C-powered kernel.

iOS, Android and Windows Phone kernels are also written in C. They are just mobile adaptations of existing Mac OS, Linux and Windows kernels. So smartphones you use every day are running on a C kernel.

Why we need to use Visual Studio Code?

Visual Studio Code Also commonly referred to as VS Code, is a source-code editor made by Microsoft with the Electron Framework, for Windows, Linux and macOS. It's a very common and widely used text editor and IDE. Features include support for debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git.

VS Code

Prerequisites for run C in VS Code

i. Download and install VS Code

Make sure to download the exact file for your operating system.


Download VS Code - Quickly find the appropriate install for your platform (Windows, macOS and Linux)

The installation process is basic. Everything you will see in the following installation process it’s going to be the same for your VS Code installation as well.

1) Select the box "I accept the agreement" and click Next.


2) Select Next


3) Select the required options as per your need by clicking in the checkbox,
e.g.: Create a desktop icon

Then select Next.


4) Select Install.


5) It might take a bit while to complete the installation.


6) Click Finish (Check in the check box to launch VS Code).


ii. Download and Install Compiler Extension

For running C or C++ code, you just need to have a valid C/C++ compiler installed on your computer.

1) Check C and C++ compilers
Open your terminal and run:

gcc --version
g++ --version
gdb --version
Enter fullscreen mode Exit fullscreen mode

If you get the version number, then the compiler is already installed on your system, otherwise you need to proceed with the next step.

2) Download the MinGW-w64 Compiler
Go to the link


3) MinGW software has been successfully downloaded.

4) Run mingw-get-setup file.

5) Click on the Install


6) Set it defaults, click on the Continue


7) After clicking the continue button, it shows step 2 of MinGW Installation Manager.


8) As we click on the Continue, it shows the below image. In the MinGW Installation Manager, we need to check the Mingw32-base package, Ming32-gcc-g++ package and Ming32-gcc-objc package to run and compile the C/ C++ program in the visual studio code.
After selecting the checkbox, click on the Installation tab (at the top left corner of the dialog box).


9) Click on Apply Changes to set the package's installation in MinGW


10) Applying the MinGW packages


11) Click on Close after all the changes have been successfully applied.


12) Set the Environment Path for the MinGW SetUp:

a. Copy the directory path, as shown below.

b. In the System Variables Path click on the Edit button, then click on the New button and then paste the C:\MinGW\bin path; after that, click OK


13) Check C and C++ compilers again now,
Open your terminal and run:

gcc --version
g++ --version
gdb --version
Enter fullscreen mode Exit fullscreen mode

The following outputs are expected now:

**gcc --version**
gcc.exe ( GCC-6.3.0-1) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

**g++ --version**
g++.exe ( GCC-6.3.0-1) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

**gdb --version**
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "mingw32".
For bug reporting instructions, please see:
Enter fullscreen mode Exit fullscreen mode

iii. Prepare VS Code for C Code

1) Go to the Extension tab. Search for "C/C++"


2) Install C/C++ Extensions


3) Install C/C++ Extensions Pack


4) Install Code Runner Extension


iv. Start C Coding

1) Here we created a Hello C folder to store the program code. Note:You can create a folder with any name in any directory.


2) Go to the VS Code and Add a Folder to a Workspace.


3) After selecting the folder, you can add files as shows below:


4) After creating the first file hello.c, write your first code


5) Run code


Much appreciated for reading the full article, I hope it be useful.

Top comments (0)