Simple C Program on Linux

0
1909

Most of us have learnt C programming in Windows platform. In Windows, the executable files or the program itself was executed with the aid of GCC compiler or Turbo C compiler that run only in Windows. Have you ever tried coding and executing a C program on Linux (Fedora or Ubuntu)? If you haven’t, here I have presented a very simple C program on Linux to help you get started with learning C on Linux (Fedora). This program will simply print “Hello World”.

Linux is a computer OS like Windows, assembled as a free and open source software. It supports a vast number of computer programming languages just like the Windows. The development tools for building programs on such programming languages comprise of GNU Compiler Collection (GCC) along with GNU build system. Some programming languages supported by Linux are C, C++, Java, Fortran, C#, Scheme, Vala, and many more.

Fedora is an Linux kernel based operating system. I have chosen the Fedora to help you start learning C on Linux, but there are many other open source OS based on Linux. These other OS include Ubuntu, Debian, etc. In my previous post, I have already discussed about how to install GCC compiler in Fedora 19 or Fedora 17. So, make sure you’ve properly installed GCC before running the code mentioned below. The source code in this post is to be compiled using GCC installed on Fedora 17.

Simple C Program on Linux - Output

After you’ve installed GCC, you can start coding, compiling and running C programs in somewhat similar environment to the Windows platform. Here, I have given a very simple example – to print “hello world”. Open the text editor “gedit” from application list and the source code for hello.c is given below.

Then, save it in your own directories or to the home directories. For compilation, you will have to provide complete path name of file as well. After doing these, you can compile, link and run the sample Linux C program.

[[email protected] ~]$ hello hello.c
[[email protected] ~]$ ./hello
hello world
[[email protected] ~]$

This simple C program on Linux is for beginners who may have learnt C program in Windows platform, but don’t know what to do to build C programs on Linux. I hope, what I explained here helped you to write your first C program on Linux platform. If you have queries, bring them up to me from the comment section.

LEAVE A REPLY

Please enter your comment!
Please enter your name here