🚀 Step-by-Step Guide: How to Run a .c File in VS Code

✅ Step 5: Open VS Code and Your C File

Once you've installed GCC and set the path correctly:

  1. Open Visual Studio Code.
  2. Open the folder where your .c file is saved.
  3. Click on the file to open it in the editor.

🛠️ Step 6: Compile the C File

In the terminal of VS Code, type the following command to compile your file:

gcc filename.c -o filename.exe

🧠 This tells the computer to take your filename.c and turn it into an executable file.

▶️ Step 7: Run the C Program

Now that you've created the .exe file, run it with this command:

./filename.exe

🎉 You should now see the output of your program!

🔁 Step 8: What to Do When You Change Code

If you make changes to your .c file, you need to:

  1. Compile it again:
  2. gcc filename.c -o filename.exe
  3. Then run it again:
  4. ./filename.exe
💡 TIP: If you want to run both commands at once, use:
gcc filename.c -o filename.exe && ./filename.exe

🎓 Bonus: Use Shortcut Extension (Optional)

If you want to run C code quickly with a shortcut:

  1. Install the extension called C/C++ Compile Run.
  2. Click the Run button or press Ctrl+Alt+N.
⚠️ This still requires GCC to be installed properly.