Howto see output of C program in Linux or UNIX

Q. I am new to Linux but not to c programming. At university we are using Turbo C compiler under DOS/Windows XP to write and compile C programs. Under Linux I’ve small program called test.c. How do I compile and see the output of C program in Linux? Note I’m using Fedora Core Linux.

A. Under Linux you need to gcc (GNU project C and C++ compiler) command to compile a program. When you compile a program it generates an executable file called a.out.

Syntax
gcc -o output-file program.c

Task: Compile program

To compile type the command:
$ gcc test.c

Task: Execute program to see output

Above command will create a file called a.out. To see output of test.c program type:
$ ./a.out

Task: Compile to specific executable file

You can specify an execuable file name while compiling program itself:
$ gcc -o test test.c
Now execute test (see output of test.c)
$ ./test

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 11 comments… read them below or add one }

1 ajay 05.25.07 at 4:38 am

yaa
you help me a lot
thnx budy

2 vivek 06.04.07 at 6:18 pm

hey man thanks for the instruction…… i can now compile and run c programs……

3 manisha 09.15.07 at 11:05 am

this is realy very nice.thanks to help me.

4 umair 01.22.08 at 5:50 pm

i have installed MinGW now pls tell how to write a program and excuate it

5 pinku 06.02.08 at 10:19 am

Hi,
from your site i came to know how to compile and see out put of program, but how to write c program in linux????I m a window user,so if anyone give me that ans i will be obliged.

6 rakesh kumar thakur 08.15.08 at 5:11 am

i search this site through google and find my answer on the topic … How can i run and compile program on gcc compiler?

7 tintin 10.23.08 at 12:18 am

Nice post. It helps newbie a lot.
:)

8 ashutosh 02.01.09 at 10:21 am

The given commands is work properly…………
it is very helpful

9 Stefaan 04.21.09 at 5:19 pm

Thanx man!!!

10 Thanks for this tip 05.08.09 at 10:01 am

Thanks for this tip
Plz also tell me how to enter the out put of one c program to another one plz send this at my email address.
Thanks for this tip

11 Avinash T M 05.21.09 at 12:52 pm

Superb information , i liked this website very much.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , , , , , , , ,

Previous post: How do I Logging in remotely from my Desktop into Linux server?

Next post: Download or install C, C++ compiler on Red Hat Enterprise Linux 5 (RHEL)