Back to C Programming
2026-07-125 min read

Step 5: Install C/C++ Extension in VS Code

Learn Step 5: Install C/C++ Extension in VS Code step by step with clear examples and exercises.

Why This Matters

Using Visual Studio Code (VS Code) with its C/C++ extension can significantly improve your coding experience by providing features such as IntelliSense, debugging, and linting. These tools help you write cleaner, more efficient code. The C/C++ extension also offers a user-friendly interface that makes it easier to manage multiple files in larger projects.

Prerequisites

Before proceeding with the installation process, make sure you have the following prerequisites:

  1. VS Code installed: Download and install Visual Studio Code from the official website.
  2. C/C++ compiler: You need a C/C++ compiler like GCC (GNU Compiler Collection) or MinGW on Windows to compile your code. If you're using Linux, chances are that the necessary tools are already installed.
  3. Terminal or Command Prompt: Access to a terminal or command prompt is essential for running commands and compiling your code.
  4. Basic understanding of C/C++ programming: This lesson assumes you have some familiarity with the C/C++ programming language. If not, we recommend learning the basics before proceeding.

Core Concept

To install the C/C++ extension in VS Code, follow these steps:

  1. Open VS Code and click on the Extensions view icon (the square with a star) located at the left sidebar.
  2. In the search bar at the top right corner, type "C/C++" and press Enter.
  3. The C/C++ extension developed by Microsoft should appear in the search results. Click on it to navigate to its page.
  4. Click on the Install button to download and install the extension.
  5. Once installed, you can verify the installation by checking for the C/C++ icon in the Activity Bar (the left sidebar).

Configuring Compiler Settings

After installing the C/C++ extension, you may need to configure the compiler settings according to your operating system and preferences. To do this:

  1. Click on the gear icon at the bottom left corner of VS Code to open the settings menu.
  2. Search for "C_Cpp" in the search bar at the top right corner.
  3. Modify the settings according to your needs, such as setting the compiler path or including additional include paths.

Worked Example

Let's walk through a simple example of using the C/C++ extension in VS Code:

  1. Open VS Code and create a new file named hello_world.c.
  2. Type the following code into the file:
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
  1. Press Ctrl + S to save the file.
  2. To compile and run the code, open a terminal or command prompt, navigate to the directory containing the hello_world.c file, and type:
gcc hello_world.c -o hello_world
./hello_world

On Windows, you might need to use MinGW's GCC instead of the default compiler. If that's the case, replace gcc with mingw32-gcc.

  1. The output should display "Hello, World!" in your terminal or command prompt.

Using IntelliSense

IntelliSense is a feature provided by the C/C++ extension that offers suggestions for function calls, variables, and more as you type. To use IntelliSense:

  1. Open the hello_world.c file in VS Code.
  2. Type printf(, and IntelliSense will suggest the correct function signature for printf().
  3. Press Enter to complete the function call, and you can then specify the format string and arguments as needed.

Common Mistakes

  1. Forgetting to save the file: After making changes to your code, don't forget to press Ctrl + S to save the file before attempting to compile and run it.
  2. Incorrect compiler usage: Ensure that you are using the correct compiler for your operating system (GCC or MinGW).
  3. Incorrect command to compile and run: Make sure you're compiling the code with gcc and running it with ./ on Linux and MacOS, or by double-clicking the output file on Windows.
  4. Not setting up the workspace: If you're working on a multi-file project, make sure to set up your workspace correctly by following the instructions here.
  5. Not configuring compiler settings: Make sure to configure the compiler settings according to your operating system and preferences after installing the C/C++ extension.

Practice Questions

  1. Install the C/C++ extension in VS Code for a new user on Windows. What steps would you follow?
  2. You have a multi-file project, and you're experiencing issues with IntelliSense. How would you troubleshoot this problem?
  3. Write a simple program that takes two integers as command-line arguments, adds them together, and outputs the result. Use the C/C++ extension in VS Code to write, compile, and run the code.
  4. Explain how to configure compiler settings for a Linux user who wants to use Clang instead of GCC with the C/C++ extension in VS Code.
  5. Describe how to set up a workspace for a multi-file C/C++ project in VS Code.

FAQ

  1. Do I need to install any additional tools or extensions for debugging my C/C++ code in VS Code?

Yes, you can use the Debugger for C/C++ extension available on the VS Code marketplace for debugging your code.

  1. Can I use other compilers like Clang instead of GCC with the C/C++ extension in VS Code?

Yes, you can configure the C/C++ extension to work with Clang by modifying the settings.json file. You can find more information here.

  1. How can I set up a workspace for my multi-file C/C++ project in VS Code?

To set up a workspace, follow the instructions here.

  1. What is IntelliSense, and how does it help me write code more efficiently?

IntelliSense is a feature provided by the C/C++ extension that offers suggestions for function calls, variables, and more as you type. This can help you write cleaner, more efficient code by reducing errors and improving readability.

  1. How do I troubleshoot issues with IntelliSense in my C/C++ project?

To troubleshoot issues with IntelliSense, first ensure that the C/C++ extension is properly installed and configured. If you're still experiencing problems, try reinstalling the extension or checking your include paths and compiler settings. You can find more information here.