πŸ”§ Setup C Language in VS Code (Step-by-Step Guide)

πŸ“Œ What is C Language?

C is a powerful and fast programming language. But it needs to be compiled before running, unlike Python or JavaScript.

A compiler converts your C code into a machine-readable format (like .exe) so the computer can understand it.

πŸ› οΈ Tools You Need to Install

πŸ“₯ Step 1: Install MinGW (C Compiler)

  1. Go to MinGW-w64 Download (SourceForge)
  2. Download and open
  3. Click install
  4. Click Continue
  5. Right click and select following :
    1. mingw-develope-toolkit
    2. mingw32-base
    3. mingw32-gcc-g++
    4. mingw32-gcc-objc
    5. msys-base
  6. Go to installation (top-left corner of the window) and click "apply changes"
  7. Close all windows
  8. Go to "My PC" and open your "C Drive"
  9. Open MinGW and open bin folder
  10. Copy the path from above
  11. Open system environment variables and paste that path creating as new path
  12. open cmd and check version : g++ --version

πŸ”— Step 2: Add GCC to System PATH

Without this step, the terminal won’t recognize the gcc command.

  1. Search for Environment Variables in Windows Search
  2. Click Edit the system environment variables
  3. Click Environment Variables...
  4. Under System Variables, select Path β†’ Click Edit
  5. Click New and paste:
    C:\Program Files\mingw-w64\mingw64\bin
  6. Click OK on all windows and restart your computer

πŸ§ͺ Step 3: Check if GCC Works

Open your Command Prompt or VS Code Terminal and run:

gcc --version

If it shows the version, you’re ready to go!

πŸ’» Step 4: Setup VS Code

  1. Open VS Code
  2. Install the extension: C/C++ by Microsoft
  3. Create a folder, then a file called hello.c
  4. Write this basic program:
  5. #include <stdio.h>
    
    int main() {
      printf("Hello, World!\n");
      return 0;
    }
          

πŸƒβ€β™‚οΈ Step 5: Compile and Run

  1. Open Terminal in VS Code (Ctrl + `)
  2. Type:
    gcc hello.c -o hello
  3. Run it:
    ./hello

    If you're on Windows:

    hello.exe
πŸ’‘ gcc hello.c -o hello means:
πŸ‘‰ Compile hello.c and make an output file named hello.exe

🐞 Common Errors and Fixes

πŸŽ‰ You're Done!

Congratulations! You now have C running on your computer like a pro coder! πŸš€