How to Write and Run a C Program in Ubuntu Linux

C stands as one of the world’s oldest programming languages across various computer systems. Programs written in C can transfer from one platform to another without requiring a complete rewrite. C isn’t limited to a specific operating system or software framework; it thrives on major platforms such as Windows, macOS, Linux, and even Android.

Creating and Running a C Program in Ubuntu Linux

Installing the C Compiler GCC on Ubuntu

To compile a basic C program, the Linux command-line tool, the terminal, proves indispensable. Open the terminal using the Ubuntu Dash or the Ctrl+Alt+T key combination.

Ensure the essential packages are installed for compiling and executing C programs. Input the following command as root in your Linux Terminal:

sudo apt install build-essential

Provide the root password when prompted, and the installation will commence. Make sure your system is connected to the internet during this process.

Writing a Simple C Program

After installing the essential packages, create a simple C program using Ubuntu’s graphical Text Editor (or any text editor like gedit). Write or copy the following sample program into the editor:

#include<stdio.h>

int main()
{
printf("\nCONNECTwww.com\n\n");
return 0;
}

sample c program

Save the file with a .c extension. For instance, name the C program helloWorld.c in this example. And save in the Home directory.

Also Read:  Carburetor Onion Routing TOR Application

Compiling the C Program with GCC Compiler

In the terminal, enter the following command to generate an executable version of the program:

gcc helloWorld.c -o helloWorld

Ensure your program is located in your Home folder, or specify the appropriate paths if it’s located elsewhere.

Running the C Program

The final step involves running the compiled C program. Utilize the following syntax:

./helloWorld

run c program in ubuntu

 

If you liked this article, please subscribe to our YouTube Channel. You can also stay connected with us on X (Twitter) and Facebook.



Leave a Reply