How to Compile and Run a C Program in Windows 10

Install Microsoft’s free Build Tools for Visual Studio with the Desktop development with C++ workload. Then open the Developer Command Prompt, compile your file with cl hello.c, and run it by typing hello.

Applies to: Windows 10. Checked against Microsoft Learn on September 28, 2026.

Install the compiler

  1. Download Build Tools for Visual Studio from Microsoft’s Visual Studio downloads page. If you already have Visual Studio, you can use it instead.
  2. Run the installer. On the Workloads tab, check Desktop development with C++.
Visual Studio Installer Workloads tab with Desktop development with C++ checked and the Install button
Check Desktop development with C++ (1), then select Install (2).
  1. Select Install and wait for it to finish. It’s a large download.

Write your program

  1. Open the Developer Command Prompt: select Start, open the Visual Studio folder, and select Developer Command Prompt for VS. The name includes your version number.
  2. Make a folder and open a new file in Notepad:
md C:\hello
cd C:\hello
notepad hello.c
  1. When Notepad asks to create the file, select Yes. Type this code and save it:
#include <stdio.h>

int main(void)
{
printf("Hello from Windows 10!\n");
return 0;
}

Make sure the file is saved as hello.c, not hello.c.txt. See how to show file extensions in Windows 10 to check.

Compile and run it

  1. Back in the Developer Command Prompt, type cl hello.c and press Enter. This makes hello.exe.
  2. Type hello and press Enter to run it.
Developer Command Prompt showing cl hello.c compiling and hello printing its message
Compile with cl hello.c (1), then run the program with hello (2).

If you see ‘cl’ is not recognized, you’re in the regular Command Prompt. Close it and open the Developer Command Prompt instead, which sets up the compiler paths for you. To learn more about the regular window, see how to open Command Prompt in Windows 10.

Useful compiler options

  • /Fe:myapp.exe names the program, for example cl hello.c /Fe:myapp.exe.
  • /std:c17 or /std:c11 compiles to a specific C standard, which some classes require.
  • /Zi adds debugging information so you can step through the program in a debugger.
  • /O2 makes the finished program run faster.

Write code in an editor

Notepad works, but a code editor helps with colors and errors. Visual Studio Code is free from Microsoft. To make sure it finds the compiler, open the Developer Command Prompt, go to your project folder, and type code . to start it from there.

Some courses use the GCC compiler instead. It’s available for Windows through projects such as MSYS2, and the commands are different, so follow your course’s setup steps.

If it won’t compile or run

  • fatal error C1034: no include path set: you’re not in the Developer Command Prompt. Open it from the Start menu and try again.
  • LNK1104: cannot open file hello.exe: the program is still running. Close its window and compile again.
  • A warning says printf isn’t defined: add #include <stdio.h> at the top of your file.
  • The program window closes right away: that happens when you double-click hello.exe. Run it from the Developer Command Prompt instead, so you can read the output.

Frequently asked questions

How do I compile more than one file?

List them all, for example cl main.c tools.c. The program is named after the first file.

Can I see more warnings?

Yes. Add /W4, for example cl /W4 hello.c.

Is the compiler free?

Build Tools for Visual Studio is a free download from Microsoft. It’s fine for learning and personal projects; check its license terms if you’re using it at a company.

Can I compile C++ the same way?

Yes. Save the file with a .cpp ending and compile it with cl /EHsc hello.cpp. The /EHsc option turns on standard C++ error handling.

Do I need to open the Developer Command Prompt every time?

Yes, or open it from Windows Terminal, where Visual Studio adds its own Developer Command Prompt profile. It sets up the paths the compiler needs, which the regular Command Prompt doesn’t have.

Can I run my program on another PC?

Usually, yes. Copy the .exe file to the other PC and run it. Small console programs work on most Windows 10 and 11 PCs. If one says a DLL file is missing, install the Microsoft Visual C++ Redistributable on that PC.

If you want to make iPhone apps instead, see can you install Xcode on Windows 10?

Microsoft’s reference is Compile a C program on the command line. More help is on our Windows Help & Guides page.

Get Our Free Newsletter

How-to guides and tech deals

You may opt out at any time.
Read our Privacy Policy