Requirements
To run a C Program on your pc you need 2 things.
- Text Editor (Notepad, Notepad++, Sublime-Text-Editor)
- C Compiler (Borland Turbo C, Tiny C Compiler, Portable C Compiler, GCC, Clang) GCC is most famous we will use GCC.
- IDE (Optional but recommended we will use
Visual Studio Code)
Installing GCC compiler
There are different ways to install GCC compiler.
First Method
- Go to the official website of
MinGW-w64Link - Click MSYS2 or directly go to Link.
- Download the installer
- Install it with the default option
- It will give you a console now run the following commands
// Update the package database and base packages
`pacman -Syu`
// Run "MSYS2 MSYS" from Start menu. Update the rest of the base packages
`pacman -Su`
// Now MSYS2 is ready for you. You will probably want to install some tools and the mingw-w64 GCC to start compiling
`pacman -S --needed base-devel mingw-w64-x86_64-toolchain`
Second Method
- Go to the official website of CodeBlock
- Clicks Downloads or direct Link
- Now click on Binary releases or direct Link
- Download
codeblocks-20.03mingw-setup.exeusing FossHUB Link (it's faster) - Install it with default options.
Now if you open your cmd and type gcc it will still not be able to find that compiler you need to set the environment variable in order to access it globally.
Setting Environment Variable
Now we will copy the compiler path and set it in out system environment variables.
- Default path for first method :
C:\msys64\mingw64\bin Default path for second method :
C:\Program Files\CodeBlocks\MinGW\binRight click on
This PCorMy Computerselectproperties. you will get following screen (Windows 11)
- Click
advance system settingson older windows this option will be on left. - Now click
Environment Variables
- Now in the System variables select path variable and press edit.
- Click New and paste you copied path and press ok.
Your environment variable is set now you can run gcc command on your whole PC.
Download and Install Visual Studio Code
We will use VS Code instead of simple notepad to write code. It's better and made to write code easily. Simple go to the official website and download and install with default options. Just remember to check Open With Code option while installation it's really helpful.
Install some extensions for better experience
Press Ctrl+Shift+X in VS Code to search for extentions. Install these extensions
- C/C++ by Microsoft
- Prettier - Code formatter
Click gear icon on bottom left and select settings. Search for mouse wheel and tick the checkbox saying Editor: Mouse Wheel Zoom
Now you are all set for writing your first code in C
Write and run your first code.
- Create folder on Desktop name is
Learning C - Drag this folder in VS Code
- Create a file named
hello.cand paste code written below
#include <stdio.h>
int main()
{
printf("Hello World from CodeWithRish!");
return 0;
}
Click terminal in options and press new terminal.
In terminal write gcc hello.c it will generate and executable a.exe if everything is setup correctly. Now type .\a.exe it will give Hello World from CodeWithRish! this output.
Hope everything is setup correctly if still there is some problem drop a comment I'll definitely help you.





Top comments (0)