Creating a C File and Compiling a Hello World Program in VSCode
To create a simple C program that prints “Hello, World!” and compile it using the command prompt in Visual Studio Code (VSCode), follow these steps:
Step 1: Create a New C File
- Open Visual Studio Code.
- Create a new file by clicking on
File
>New File
or using the shortcutCtrl + N
. - Save the file with a
.c
extension. For example, you can name ithello_world.c
by clicking onFile
>Save As
and entering the filename.
Step 2: Write the Hello World Program
In the hello_world.c
file, write the following code:
hello_world.c
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
To execute the program, follow these steps:
- Open the command prompt.
- Navigate to the directory where the
hello_world.c
file is saved. - Compile the program using the command
gcc hello_world.c -o hello_world
. - Run the program by typing
hello_world
and pressing Enter.