How to write and run a C language program on Linux?

To write and run C language programs, you need to install a C compiler first. On Linux, a commonly used C compiler is GCC (GNU Compiler Collection). Here are the steps for writing and running C language programs on Linux:

  1. Open the terminal.
  2. Update the system with the command “sudo apt update” and install necessary build tools with “sudo apt install build-essential”.
  3. file named hello.c
  4. edit the file hello.c using nano
  5. #include

    int main() {
    printf(“Greetings, Earth!\n”);
    return 0;
    }

  6. Save and close the file.
  7. Compile the hello.c file using GCC and generate an executable named hello.
  8. greetings
  9. execute the hello program
  10. Greetings, Earth!

Please note that the steps above are performed on Ubuntu or Debian-based Linux distributions. For other Linux distributions, you may need to use a different package manager to install the GCC compiler.

bannerAds