How C Program is run in Linux
C program code is first compiled by a compiler which converts the strings-based code into machine code that can be readable by a computer machine. In Linux, the most common compiler used for C programming is GCC compiler and is available in the default repository of the many distributions of Linux that can be installed easily using the apt package manager:
Once the GCC package has been installed, now it’s time to create a file using the nano editor with the name myfile.c, (“.c” is the extension that tells the computer that this file contains a C program):
Write the simple code in the C language of printing “Hello Linux Hint! ”:
In the above code, we included a header file the stdio, which is used to include input and output related information, the main() is the function of the program, printf is used to print the output, and return 0 is the exit status.
Press CTRL+S to save the file and exit the editor by pressing CTRL+X. List down the contents of the file by using the ls command to verify the creation of the file:
The file is being successfully created, to compile the file using the GCC compiler, run the following command:
In the above command the gcc is the compiler that compiles the file which was created with the name of myfile.c and then checks whether it has an error or not, and if there is no error, then the “myfile” (binary file) will be generated in the same directory. To execute the binary file use:
In the above output, we have seen that the output of our C program has been displayed.
Conclusion
In this era of Information technology, everyone is keen to learn coding. C programming is recommended to beginners from which they can start learning and besides this, C programming is a general-purpose language that can be used not only for learning the basics of programming but also on advanced level development of applications. In this post, we learned how the GCC compiler is used in Linux to compile the C program. Other than the terminal, there are different compilers like Visual Studio that are GUI(Graphical User Interface) based which can be installed on Linux to compile and run C programs in Linux.