More

    Install C in Windows Easiest Way!

    - Advertisement -

    If you struggle to correctly install C in Windows PC with Visual Studio Code and MinGW, then your struggle ends here. In this article, I’ll guide you on how to properly install and configure C in Windows with Visual Studio Code and MinGW.

    c in windows




    Follow the steps given below to install and configure C in Windows:

    Step 1: Installing VS Code

    The first step is installing Microsoft Virtual Studio Code on your Windows. Well, one can use other code editors too, like Sublime Text Editor, but I would recommend you install Microsoft’s Visual Studio Code. To install VS code, follow the steps given below :




    • Click here to visit the download page of Visual Studio Code.
    • After that, click on the Windows button to start downloading VS Code for Windows.

      Vs Code Download

    • You’ll see thank you message, and your visual studio code will start downloading.

      Vs Code Downloading

    • After the Visual Studio Code setup is downloaded, run the setup and accept the agreement. After that, click on the next button.

      VS code setup

    • Select the destination where you want to install Visual Studio Code and then click on the Next button.

      Vs code select destination

    • Select the Start Menu folder and then click on the Next button. I would recommend you to leave it as it is and then click on the Next button.
      - Advertisement -

      vs code select start menu

    • In the Select additional tasks section, make sure to check all the boxes and then click on the Next button.

      VS code setup select additional tasks

    • Now Visual Studio Code is ready to get installed, so click on the Install button to start installing Microsoft Visual Studio Code.

      VS Code ready to install

    • The installation will take some time, and after it is completed, click on the finish button to exit the VS code setup.

      VS code installation completed

    Now that we’ve installed Microsoft Visual Studio code to write our C programs. Let’s install the MinGW compiler for our C Programs.




    14 Amazing VS Code Tips To Increase Productivity And Speed

    Step 2: Downloading and setting up MinGW For C in Windows

    In this step, we are going to download MinGW and set it up so that we can compile our C programs in windows without any errors.

    • Click here to visit the download page of MinGW.

      mingw-download-page

    • Download the latest version of MinGW from the download section.
    • After the download is completed, run the MinGW setup and then extract it in Local Disk C. Anyway, you can extract it anywhere but I would recommend you extract it in Local Disk C.

      mingw-extract

    • After the extraction is completed, you’ll see the MinGW folder at the place you extracted it. In my case, it is in Local Disk C cause I extracted the MinGW setup in Local Disk C.
      - Advertisement -

      mingw-folder

    Now that we’ve installed MinGW, let’s set up the environment variable path for MinGW in windows so that we can compile and run C/C++ programs in Windows.




    Setting Up Environment Variable For C In Windows

    • To set up the environment variable path for MinGW, get inside of bin folder that is in the MinGW folder.

      mingw/bin folder for c/c++ in windows

    • Copy the path of this folder from the address bar of file explorer.

      mingw path for c in windows

    • Now right-click on This PC and then click on Properties.

      mingw setup path for c in windows

    • Now from properties click on Advanced system settings.

      setting up path for mingw for c++ in windows

    • From Advanced system settings, click on Environment Variables.

      advanced system settings

    • Now in Environment Variables, select Path and then click on Edit.

      environment variables for c++ in windows

    • Here click on the New button to create a new path and then paste the path you’ve copied and then click on the OK button to save it.

      mingw path for c++ in windows

    - Advertisement -

    We’ve successfully set up MinGW and its path for environment variables so that we can use GCC to compile and run C in Windows PC.




    Checking MinGW Installation

    To confirm if MinGW is installed or not properly on your Windows PC. Type the gcc command in your windows terminal. If you see a fatal error message, as shown in the image below, that means you’ve installed MinGW in your Windows properly.

    gcc for c in windows
    gcc installed successfully

    You can also check your GCC version using the command gcc --version in your terminal.

    gcc --version command for c in windows
    gcc –version




    Installing C/C++ IntelliSense In VS Code

    Now we are ready to write and run C in Windows PC, but before that, I would like to tell you about a VS code extension that will help you write C code.

    C/C++ Intellisense is a VS Code extension that helps write C/C++ code faster. So to install it get in the VS code extensions section, search for “C/C++ IntelliSense and then Click on the Install button to install it.




    Running C/C++ Program

    Now that we’ve set up everything required to write and run C/C++ in windows, let’s run a simple hello.c program in our windows.

    To run a C program, we need to compile it using GCC. So to compile your C code, type gcc and then the file name of your code in the terminal and hit enter. In my case, to compile hello.c code I need to type gcc hello.c in my terminal.

    gcc <file-name> #To compile code
    gcc hello.c

    It will take a few seconds to compile after it is done, you’ll see a new file with the .exe extension. In my case, it was a.exe, this exe file is your compiled code. Now to run the code type ./ and the file name in the terminal. So In my case, I need to type ./a.exe to run my code, and then I’ll see the results.




    example to run c in windows

    Conclusion

    So this is how you can set up C in Windows PC to write and run C code. If you are stuck somewhere, whether in setting up MinGW or running C code watch my YouTube video given below to understand it.

    - Advertisement -

    Recent Articles

    Leave A Reply

    Please enter your comment!
    Please enter your name here