Executing C programs in Linux

A lot of use Windows as our operating system, but of late people started using Linux along with it. This is the article for programmers who would wish to use Linux for their programming purpose.

First create a C program using your text editor. Let it be “hello.c”

Now open the terminal and type

 “$ gcc hello.c”.

Here “$” symbol is the prompt and one need not type it again.

Now gcc will create an output file called “a.out” by default.

Next you type following command  the terminal to execute the  C program

$ ./ a.out.

If you execute too many programs in the same directory then each time the a.out file will get replaced. To avoid this use the following format,

 gcc -o <outputfilename> filename.c.

In this output file  will be created with the name specified by you.

Eg: For the above program you can type

gcc -o hello hello.c.

The file will be created with the name hello. Then you can execute the program by typing   $./hello.c

Advertisements

About aronnirmal

A student pursuing Masters in Compter Applications. Intrested in Linux, Computer Hardware and networking,eco-enviorment related issues and politics.

Posted on March 29, 2010, in Information, linux, Open source, Technical and tagged , , . Bookmark the permalink. Comments Off on Executing C programs in Linux.

Comments are closed.

%d bloggers like this: