How to run C program

2025-08-04

How to run C program on windows

  1. Visual studio has a built-in C compiler.
  2. Run "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x64 in cmd to set up the environment. Note: It cannot run on powershell 7+.
  3. Use cl command to compile C files, e.g., cl test.c -o test.exe.
  4. Run the compiled program with test.exe.

Alternative or must way on Windows

  • Use developer powershell for VS2022 will resolve the above hacks.
  • Just open a new terminal with Developer Command Prompt for VS 2022 or Developer PowerShell for VS 2022.
  • Then cl command will work without any additional setup.