Menu Close

Getting started with C/C++ Programming using VS Code

In this article we will learn about how to Getting started with C/C++ Programming using VS Code. Here we will discuss how we can configure to use C/C++ programming in Visual Studio Code. Please read my all articles of .NET here.

Prerequisites

  • We should have a basic knowledge of C programming.
  • The Visual Studio Code Editor must be installed in the system, you can find here the link to download VS Code.
  • Download the C/C++ Extension. It is an extension provided by Microsoft that support visual studio code. It helps in Intelligence, debugging and code browsing of the programming code in the visual studio.
  • Download the C/C++ compilers.

Why should you use visual studio code ?

Visual Studio Code is a free source-code editor made by Microsoft for Windows, Linux and macOS. Features include support for debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git.

In this post you will learn how to set up visual studio code on your local environment for C and C++, this can get lengthy but if you follow step by step you can set it up easily.

Install the C/C++ VS Code Extension

I have already installed the Visual Studio Code for my other programming stuffs. Open the VS Code and install the C/C++ extensions.

Default VS Code look
  • Move to the extension on the left menu as on Red highlight and search here as C extension.
  • Install the highlighted C/C++ extension.
Install C Extension

Download and Install Compiler Extension

A MinGW is an advanced GCC compiler software used to compile and execute code.

This software supports only the window operating system.

Download the MinGW-w64 Compiler

Navigate to this link and click on the download.

Install MinGW

  • Open the installer, you should see something like the below image. Click on install and choose your directory where the software should be installed and click continue.
  • After clicking the continue button it is processed to install then hit continue button.

mingw-exe
  • After installing, click on continue and right click on every checkbox and choose mark for installation. After checking all checkboxes you should see something like image below.
  • Now click Installation on top left corner and then choose Apply Changes. You should see something like shown in the image below.
  • Then click on apply. Once you complete the installation, you should see something like the image below.

Setting up the Environment Path for the MinGW

After downloading and installing the MinGW compiler, we now set the environment path to include the C/C++ compiler directory.

  1. Go to the installation directory of the MinGW Set Up. Here we installed the setup at the D drive, as shown below and navigate to bin folder and copy this path.

  • On the windows search type as Edit System Environment
  • Click on the Environment Variables it popup the next screen and select the system variables path and Edit it.
  • Now click on new and paste the bin path that we have copied in the previous step and then click Ok.

Also I have added this path in the user variables, as I’m getting issues to check the gcc --version

Let’s check if MinGW has been successfully installed or not.

Open the terminal window and write the command to check the MinGW Compiler is not installed or not.

gcc --version

Let’s write our first program in C

  • Create a new folder named as hello-world and create a new file named as hello-world.c
  • Create the sample C program that print the text.
  • Right click on the code and you can see the Run code(this come after installing the extension code runner) and hit the point.
#include <stdio.h>
void main()   // define the main function  
{  
    printf("Welcome to World of C");  // print the statement.  
}  

The output should be like below,

Conclusion

So far this article we learnt about how to Getting started with C/C++ Programming using VS Code. We discuss here how we can use the VS Code and compiler work in C.

Leave behind your valuable queries and suggestions in the comment section below. Also, if you think this article helps you, do not forget to share this with your developer community. Happy Coding 🙂

Jayant Tripathy
Coder, Blogger, YouTuber

A passionate developer keep focus on learning and working on new technology.

Leave a Reply

Your email address will not be published.