How To Use the C Programming Language in Ubuntu 22.04

If you are passionate about learning the programming languages then it will be recommended to start with the C programming as it is the basics of all programming languages with an easy and understandable syntax. When you learn the C programming language, then it is easy for you to work with the other programming languages as only the syntax will be different.

If you are using the Ubuntu operating system and deciding to start with the C programming language tutorials then you are on the right path, as in this guide, we will explore the method to use the C programming language in Ubuntu 22.04.

How to use the C programming language on Ubuntu 22.04

To use the C programming language, first, we have to make sure that the compiler and other required packages of the C programming language have been installed. But before going to the usage, we will open the terminal and update the repository and packages of Ubuntu by using the command:

$ sudo apt update

GCC includes all the files and libraries which are used to compile and run the code of C programming language, so we will make sure the GCC package is installed and if not, then use the command mentioned below to install it:

$ sudo apt install gcc -y

To confirm the installation of GCC, we will display the version details of installed GCC using the command:

$ gcc --version

Now we will write a simple program of the c programming language to display “Hello Linux” for five times by using the for loop, for this open the file with the name of mycode with .c extension:

$ nano mycode.c

Copy-paste the script mentioned below:

#include <stdio.h>
int main() {    
    for (int i=0; i<5; i++)
    printf(“Hello Linux \n”);
    return 0;
}

Exit the nano editor by saving the file and compile the mycode.c file using the gcc compiler:

$ gcc -o mycode mycode.c

After compiling the file by executing the above command, a binary file is generated with the name of “mycode” in the same directory and to run the output of the above C program, we will use the command:

$ ./mycode

Conclusion

C programming is the most popular and still widely used for the development of different applications and it can be used on any operating system. In this write-up, a simple c program is being compiled and run for the understanding of the readers to use the C programming language on Ubuntu 22.04.

Over 500 Million Views on Our Blogs and YouTube! We’re inviting 10 businesses to partner with us and grow together. Click here to join us! ×