Visual Studio Code Setup for C  Programming

Visual Studio Code Setup for C Programming

ยท

3 min read

Written by Pritam

What is VS Code ๐Ÿค”

Visual Studio Code (VS Code) is a lightweight and versatile code editor. It's widely used for programming due to its user-friendly interface, extensive extension support, and cross-platform compatibility, making it a popular choice for developers.

Download & Install VS Code

Search on Google for VS code and download it from its official website

Install VS Code with all default

Download & Install Compiler :

C is a compiled language, which means that it is converted into machine code before it can be executed. So we need a compiler. GCC is a widely used compiler in the case of Windows we'll download MinGW, or "Minimalist GNU for Windows" (MinGW is a port of the GNU Compiler Collection (GCC) to Windows.)

What is a Compiler? ๐Ÿคฏ : A compiler is a software tool that translates high-level programming code into machine-readable code. Its primary role is to convert human-readable code into a format that a computer's central processing unit (CPU) can understand and execute.

  • Install MSYS2 with all default

  • Click on the finish in the installer by checking RUN MSYS2 now

  • Then install MinGW by running this ๐Ÿ‘‡ command in the MSYS2 terminal

  pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
  • Then enter default=all in the terminal and then y for yes

  • If any error occurs press the upper arrow button on the keyboard and run the command again to make sure all operations are completed

  • Then run this ๐Ÿ‘‡ command to check the GCC version it also ensures that the compiler (GCC) is properly installed or not

  •       gcc --version
    

Add MinGW's bin directory to your system PATH

What is PATH and Why Include It?: The PATH environment variable is a set of instructions that guides the operating system to locate executables or program files. Including the PATH during installation is crucial as it ensures the system can find and execute the commands associated with installed software, such as a C compiler.

  • First copy the bin folder -> open file explorer -> OS(C:) -> msys64 - > ucrt64 -> bin

  • Single click on the top bar in the file explorer to select the path and press Ctrl + c to copy the path

  • Generally, the path is C:\msys64\ucrt64\bin

  • Now click on the start menu and search for edit environment variables

  • Edit the PATH : Path -> Edit -> New -> Ctrl + V -> Ok -> Ok

Additional Settings for VS Code

Installing Extension for C

  • Open VS Code: Start -> Search VS Code -> Click

  • Download Two extensions named C/C++ and Code Runner

  • To download extensions click on extensions in the top left bar in VS code then search for particular extension and install

    Settings for run code in terminal and save before run

  • Click on settings and then search run code in the terminal and check the following box

  • Click on settings and then search save before run

Writing and Running Your First C Program

  • Open VS Code click on Open folder

  • Then create a New folder by Ctrl + Shift + N name it and select it to open in VS Code

  • Create a new file, the file extension should be .c like here tutorial.c

  • Write a simple to-print a text from the upper corner click on the small drop-down and click run code

ย