Table of contents
Unlike Python, there's no real need to install C separately, It is already in our system. However, to execute C code, we need to setup a compiler. We will focus on using the GCC compiler here.
Setup MinGW
To setup GCC on Windows, we must install MinGW, which supports GCC on Windows.
We first install MinGW from SourceForge. And then run the executable.
After we click 'Install' on the wizard, click next.
Then we select whatever packages we need for C development:
Here, 'mingw32-base' and 'mingw32-gcc-g++' are best, so we only check those.
Set Environment Variables
In order for MinGW to be accessible from any directory, and through any code editor like vscode by default, we must add it to our $PATH.
In order to do that, we search "environment variables" on the search bar, and open it.
We click on environment variables at the bottom left.
Then we click on 'PATH' and click on 'new', we paste the following and click OK
C:\MinGW\bin
After we close all the windows, we can fire up our terminal and get started finally.
Using GCC
In order to use GCC, we must first write a C file, it must have an extension of .c
.
We first compile our code
gcc <file_name>.c -o <file_name>.exe
This will store the executable for our C code into another file with the same name (except the extension).
Then we run the file.
.\<file_name>.exe
We can also do all of this in one go.
gcc <file_name>.c -o <file_name>.exe && .\<file_name>.exe
Online alternatives
We can write and run our C code on online platforms like OnlineGDB or Replit as well.