Short answer: Yes, you need to rename .cpp files to c, so you can write C: https://msdn.microsoft.com/en-us/library/bb384838.aspx?f=255&MSPPError=-2147217396

From the link above:

By default, the Visual C++ compiler treats all files that end in .c as C source code, and all files that end in .cpp as C++ source code. To force the compiler to treat all files as C regardless of file name extension, use the /Tc compiler option.

That being said, I do not recommend learning C language in Visual Studio, why VS? It does have lots of features you are not going to use while learning C

Answer from 72DFBF5B A0DF5BE9 on Stack Overflow
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › build › walkthrough-compile-a-c-program-on-the-command-line
Compile a C Program on the Command Line | Microsoft Learn
Next, verify that the developer command prompt is set up correctly. In the command prompt window, enter cl (or CL, case doesn't matter for the compiler name, but it does matter for compiler options).
Discussions

how to run program in c in visual studio code
Hi, I am using visual studio code version 1.107.1 (user setup). for learning programing in "C" . I need help to setup studio code, to create workspace, file and run the debug . I have setup c/c++ , c/c++run extension. I have download gcc compiler and verified in cmd. More on learn.microsoft.com
🌐 learn.microsoft.com
1
1
Want to compile and run C programs on Visual Studio 2022
Visual Studio supports compiling C with the C++ toolchain, you just need to set the required options. You can create a C-language project by using C++ project templates. In the generated project, locate files that have a .cpp file name extension and change it to .c. Then, on the Project Properties page for the project (not for the solution), expand Configuration Properties, C/C++ and select Advanced. Change the Compile As setting to Compile as C Code (/TC). https://docs.microsoft.com/en-us/cpp/build/reference/visual-cpp-project-types?view=msvc-170&viewFallbackFrom=vs-2017 More on reddit.com
🌐 r/learnprogramming
1
2
January 1, 2022
Can I compile pure C code in Visual Studio?
Hello, Can I compile pure C code in Visual Studio? We can change the extension file to .c but I think the code compiles in Visual C++. I want to compile C code in C compiler in Visual Studio, not in C++ compiler. Thank you More on learn.microsoft.com
🌐 learn.microsoft.com
1
0
February 27, 2022
Hi How to run a c program on visual studio community 2022?
One single file cannot be built or run in Visual Studio. You can try to create a new project by using project templates that provided by VS, and type, edit the code in newly created project, then run your program. More on learn.microsoft.com
🌐 learn.microsoft.com
1
0
April 28, 2024
🌐
Stack Overflow
stackoverflow.com › questions › 65598881 › how-to-compile-c-program-in-visual-studio-code
How to compile C program in Visual Studio Code? - Stack Overflow
Choose your newly installed compiler (GCC or Clang) from the prompt. It will compile the code and print "Hello world!" in the terminal at the bottom
🌐
Visual Studio Code
code.visualstudio.com › docs › languages › cpp
C/C++ for Visual Studio Code
November 3, 2021 - C++ is a compiled language meaning your program's source code must be translated (compiled) before it can be run on your computer. The C/C++ extension doesn't include a C++ compiler or debugger, since VS Code as an editor relies on command-line tools for the development workflow.
🌐
Medium
ludwiguer.medium.com › configure-visual-studio-code-to-compile-and-run-c-c-3cef24b4f690
Configure Visual Studio Code to compile and run C/C++ | by Luis Guerrero | Medium
April 6, 2020 - Or we can open VSC, go to Code > Preferences > Extensions (also using the shortcut shift + cmd + X) type C++ and press install. ... The next extension is to actually compile and run our code, I picked Code Runner, we can download it from here, ...
🌐
freeCodeCamp
freecodecamp.org › news › how-to-write-and-run-c-cpp-code-on-visual-studio-code
How to Write And Run C and C++ Code in Visual Studio Code
January 20, 2023 - Before approaching the process of running your first C or C++ code on Visual Studio Code, let me guide you through the process and get it all set up based on the operating system you are using on your computer. For running C or C++ code, you just need to have a valid C/C++ compiler installed ...
Find elsewhere
Top answer
1 of 1
1

To run a C program in Visual Studio Code, follow these steps:

  1. Install the C/C++ Extension: Ensure you have the C/C++ extension installed in Visual Studio Code. You mentioned you have this set up, which is great.
  2. Set Up a Workspace: Create a new folder for your C projects. Open Visual Studio Code and select File > Open Folder... to open your newly created folder.
  3. Create a C File: Inside your workspace folder, create a new file with a .c extension (e.g., hello.c). You can do this by right-clicking in the Explorer pane and selecting New File.
  4. Write Your Code: Write your C code in the newly created file. For example:
       #include 
       
       int main() {
           printf("Hello, World!\n");
           return 0;
       }
    
  5. Configure Build Tasks: You need to set up a build task to compile your C code. Press Ctrl + Shift + B to open the build tasks menu. If prompted, select Create tasks.json file from template and choose Others. Modify the generated tasks.json file to include the following:
       {
           "version": "2.0.0",
           "tasks": [
               {
                   "label": "build",
                   "type": "shell",
                   "command": "gcc",
                   "args": [
                       "-g",
                       "${file}",
                       "-o",
                       "${fileDirname}/${fileBasenameNoExtension}"
                   ],
                   "group": {
                       "kind": "build",
                       "isDefault": true
                   },
                   "problemMatcher": [
                       "$gcc"
                   ],
                   "detail": "Generated task by gcc"
               }
           ]
       }
    
  6. Build Your Program: Press Ctrl + Shift + B again to build your program. This will compile your C code and create an executable in the same directory.
  7. Run Your Program: Open the terminal in Visual Studio Code (View > Terminal or `Ctrl + ``) and run your program by typing:
       ./hello
    
    (Replace hello with the name of your executable if different.)
  8. Debugging: To debug your program, you will need to set up a launch configuration. Go to the Run view (left sidebar) and click on create a launch.json file. Choose C/C++: g++ build and debug active file. This will create a launch.json file where you can configure debugging settings.
  9. Start Debugging: Set breakpoints in your code by clicking in the gutter next to the line numbers. Then, press F5 to start debugging your program.

By following these steps, you should be able to set up Visual Studio Code for C programming and run your code successfully.


References:

  • Walkthrough: Compile a C program on the command line
🌐
Reddit
reddit.com › r/learnprogramming › want to compile and run c programs on visual studio 2022
r/learnprogramming on Reddit: Want to compile and run C programs on Visual Studio 2022
January 1, 2022 -

Guys CS Major here, uni is teaching with C and I want to build C programs (Not C++). I can go ahead and install code blocks, but I really want to use VS 2022 only. I know there is probably a way to make it but I dont seem to understand the linking of compiler. Can you guys please help me in installing it on Visual Studio 2022

I had VS Code to do my stuff which probably ran once and then gave some error. Since then I use online compilers to do stuff. The compiler was MinGW

Also I installed the C++ desktop environment on the Visual Studio community edition but when I go on to run the thing with #include <stdio.h> and stuff it does not recognise it.

🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 752405 › can-i-compile-pure-c-code-in-visual-studio
Can I compile pure C code in Visual Studio? - Microsoft Q&A
February 27, 2022 - A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation. ... Unless you're setting the /Tp or /TP compiler options, .c files should compile as 'C', not C++. What makes you think otherwise? ... If the extension is .c, or the "Compile As" option for file is "Compile as C Code (/TC)", then you cannot use class, new, etc.
🌐
DEV Community
dev.to › haythammostafa › run-c-code-in-visual-studio-code-2j86
Run C Code in Visual Studio Code - DEV Community
July 3, 2023 - In the MinGW Installation Manager, we need to check the Mingw32-base package, Ming32-gcc-g++ package and Ming32-gcc-objc package to run and compile the C/ C++ program in the visual studio code.
🌐
HackerNoon
hackernoon.com › how-to-compile-cc-code-in-vs-code-windows-gy4l35g1
How to Compile C/C++ Code in VS Code (Windows) | HackerNoon
March 16, 2021 - How to Compile C/C++ Code in VS Code (Windows): To compile C/C++ code we need GCC/G++ to compile the code but Windows doesn't have a terminal.
🌐
GitHub
gist.github.com › akanshgulati › 56b4d469523ec0acd9f6f59918a9e454
Visual Studio Code task to compile and run C programs · GitHub
Clone this repository at &lt;script src=&quot;https://gist.github.com/akanshgulati/56b4d469523ec0acd9f6f59918a9e454.js&quot;&gt;&lt;/script&gt; Save akanshgulati/56b4d469523ec0acd9f6f59918a9e454 to your computer and use it in GitHub Desktop. ... The below code is the configuration for the Microsoft Visual Code tasks which will enable you to compile and run C program
🌐
Quora
quora.com › How-do-I-compile-and-run-C-in-Visual-Studio-Code
How to compile and run C++ in Visual Studio Code - Quora
Answer (1 of 3): Hey, 1. Install C/C++: So, the first step Step is to install C/C++ extension on your VS code. Go, to the last 4 square option in the left bottom of given options. Here , I given the snap shot of the same : 2. Install Code Runner: After, u have successfully installed the previou...
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1661018 › hi-how-to-run-a-c-program-on-visual-studio-communi
Hi How to run a c program on visual studio community 2022? - Microsoft Q&A
April 28, 2024 - If the code you have is from an existing project, try to get the whole project and open the project(File => Open => Project/Solution) in Visual Studio then run it. Besides, it seems that the code you have(from the screenshot) is C#, but you want to use/run a C/C++ program?
🌐
PW Skills
pwskills.com › blog › cpp › c-programming-in-vs-code
Can I Use C Programming in VS Code? Explained in Detail!
October 30, 2025 - Configure Compiler in VS Code: Open the VS Code settings, navigate to the C/C++ configurations, and set the "compilerPath" to the path of the installed C++ compiler. Create a New C File: Open VS Code, create a new C file with a .c extension, ...
🌐
LearnTube
learntube.ai › home › digital marketing › how to compile your c++ code in visual studio code
How To Compile Your C++ Code in Visual Studio Code - Learn Tube
October 13, 2022 - In VS Code, install the Code Runner extension: Let’s install Code Runner now that we’ve completed setting up our compiler. Code Runner lets you run code snippets or entire code files in a variety of languages, including C, C++, Java, JavaScript, PHP, Python, Perl, Perl 6, Ruby, Go, Lua, Groovy, PowerShell, BAT/CMD, BASH/SH, F# Script, F# (.NET Core), C# Script, C# (.NET Core), VBScript, TypeScript, CoffeeScript, Scala, Julia, Crystal, OC. After installing restart the Visual studio code.
🌐
Hive
hive.blog › hive-148441 › @pakgamer › how-to-compile-your-c-c-code-on-the-visual-studio-code
How to Compile your C/C++ code on the Visual Studio Code. — Hive
June 23, 2020 - In previous tutorials, we used Dev C++ because we were not able to run our script on the VS code. SO in this post, I am going to fix the problem. We are going to configure the Visual Studio Code for C++. To compile our code on VS code we need to install few things and configure our setting ...
🌐
Quora
quora.com › How-can-I-run-a-C-program-in-a-Visual-Studio-Code
How to run a C program in a Visual Studio Code - Quora
Answer (1 of 8): * You should first go to option create a new project in file menu. * Then enter the name of project press OK and accept the defaults and press finish. * Then a new terminal is opened for you on the screen . * Then you should type a syntactically correct program. [code]For exa...