Run C Files in Linux: Complete Guide

To create and run a C file in Linux, you can follow these steps:

  1. 1. Create a new C file, such as hello.c, using any text editor like vi or nano. Write your C code in the file, for example:
#include <stdio.h>

int main() {
    printf("Hello, world!\n");
    return 0;
}
  1. Save and exit the text editor.
  2. Open the terminal and use the gcc compiler to compile your C file. Enter the following command in the terminal:
gcc -o hello hello.c

This will create an executable file named hello.

  1. Run your executable file. Enter the following command in the terminal.
./hello

You should see the output “Hello, world!”.

In this way, you have successfully created and run a C file. You can follow similar steps to create and run other C files.

bannerAds