Writing and executing a simple C program

Home / C Programming / Writing and executing a simple C program

Writing and executing a simple C program


To write and execute a simple C program, follow these steps:

Set up a development environment: Install a C compiler on your computer. Popular options include GCC (GNU Compiler Collection) for Linux, MinGW for Windows, or Xcode Command Line Tools for macOS.


Choose a text editor or an integrated development environment (IDE) to write your code. Examples include Notepad++, Visual Studio Code, or Code::Blocks.

Open your chosen text editor or IDE and create a new file with a .c extension. For example, you can name it "simple_program.c".

Write the C code in the file. Here's an example of a simple program that prints "Hello, World!" to the console:


Save the file.

Open a command prompt or terminal and navigate to the directory where you saved the C file.

Compile the C program using the C compiler. The exact command depends on the compiler you're using. For example, with GCC, you can use the following command:

This command tells the compiler to generate an executable file named "simple_program" from the source file "simple_program.c".

If there are no compilation errors, you should see the executable file in the same directory.

Execute the program by running the generated executable file. Use the following command: