How to write and run a C program in Debian 10

Debian and Linux are becoming increasingly popular with software developers as an open and free operating system. In this article, we will describe how to write, compile and run a simple C program in Debian. This will serve as the basis for your transition to more complex and useful C programs that you can write and run on Linux.

We followed the steps and commands mentioned in this article on a Debian system with 10 boosters, and we will use the Linux command line, terminal, to compile a simple C program.

Step 1. Install C-Compiler and Build Tools

To compile and execute the program in C, you need to install the necessary packages on your system. Enter the following commands as root in your Debian terminal:

$ sudo apt-get update

(This command allows you to install the latest version of the program from online storage.)

$ sudo apt-get install build-essential

You will be asked to enter the password for the root user; After that, the installation process will begin. Please make sure you are connected to the Internet.

Step 2: Write a Simple C Program

After installing the necessary packages, we will write a simple C program.

Open the Debian graphical text editor, run gedit and write or copy the following sample program into it:

#include
int main()
{
printf("nA sample C programnn");
return 0;
}

Then save the file with the extension .c. In this example, I call my C program as sampleProgram.c

Program example

Alternatively, you can write a C program through a terminal in gedit as follows:

$ gedit sampleProgram.c

This will create a .c file where you can write and save the program.

Step 3: Compile a C Program

Enter the following command in your terminal to create an executable version of the program you wrote:

Syntax:

$ gcc [programName].c -o program_name

Example:

$ gcc sampleProgram.c -o sampleProgram

Compile a C program with gcc (GNU C Compiler)

Make sure your program is in your home folder. Otherwise, you will need to specify the appropriate path in this command.

Step 4: Run the program

The final step is to run the compiled C program. To do this, use the following syntax:

$ ./programName

Example:

$ ./sampleProgram

Run the compiled program

You can see how the program runs in the above example, displaying the text we wrote to print through it.

In this article, you learned how to write, compile, and run a simple C program in the Debian 10 Buster. All you need is the packages you need to build and the skills you need to make you a Linux programming guru!

How to write and run a C program in Debian 10

Sidebar