C language is one of the earliest programming languages. It is simple and easy to learn. Formerly C programming was performed on Turbo C, a discontinued integrated development environment. But nowadays it can be easily executed on different operating systems.
In this guide, you will learn how to write your first C program using the Linux operating system which requires just the GNU C compiler and a text editor and not a full blown integrated development environment to get started. The following steps will show to install a GNU C compiler on Linux, how to write the source code, compile and execute the C program.
To execute a C program on Linux, you need to install the following :
For C programming it is essential to install a compiler that will compile the program before executing. In Linux operating system type the following command in terminal to install the GNU C compiler which is one of the most famous compilers for Linux:
$ sudo apt-get update
$ sudo apt-get install build-essential manpages-dev
Output:
Install C Compiler and Toolchain" width="720" height="405" />
To ensure that your compiler is installed type the given command to find its location and version number:
$ whereis gcc
Output:
$ which gcc
Output:
$ gcc --version
Output:
To start writing your source code, open a text editor by typing
$ gedit program.c
Write the C source code given below in text editor:
#include
main()
printf("This is my first C program on ubuntu\n");
>
Close the editor window.
Output:
The following command will invoke the GNU C compiler to compile the file program.c and output (-o) the result to an executable called program.
$ gcc -o program program.c
Output:
Type the given command to display output:
$ ./program
Output:
The above guide demonstrates how to write your first C program in Linux by installing GNU C compiler. To know more about C programming in Linux explore different books and practice more source code related to different topics in C programming.
OSNote covers tutorials and stories about Linux and OpenSource Software.