Howto see output of C program in Linux or UNIX

by Vivek Gite on April 9, 2007 · 35 comments

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

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 35 comments… read them below or add one }

1 ajay May 25, 2007

yaa
you help me a lot
thnx budy

Reply

2 firoz July 1, 2010

wt is the process to get output in c program

Reply

3 vivek June 4, 2007

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

Reply

4 manisha September 15, 2007

this is realy very nice.thanks to help me.

Reply

5 umair January 22, 2008

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

Reply

6 pinku June 2, 2008

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.

Reply

7 rakesh kumar thakur August 15, 2008

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

Reply

8 tintin October 23, 2008

Nice post. It helps newbie a lot.
:)

Reply

9 ashutosh February 1, 2009

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

Reply

10 Stefaan April 21, 2009

Thanx man!!!

Reply

11 Thanks for this tip May 8, 2009

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

Reply

12 Avinash T M May 21, 2009

Superb information , i liked this website very much.

Reply

13 bhargav July 19, 2009

i am executing c program in fedora as gcc temp.c but it says that
bash: gcc: command not found
please tell how to run

Reply

14 Vivek Gite July 19, 2009
15 neeraj sinha July 28, 2009

@bhargav:
Update your YUM repo (in Fedora/ RHEL), thereafter
run the following command as root:
yum install gcc
or simply write
sudo yum install gcc
have fun!

Reply

16 Ivneet August 17, 2009

I am successfully executing a C prg in Turbo C but i am getting a runtime error in gcc. Please help

Reply

17 neeraj sinha August 18, 2009

@Ivneet:
Please be specific about your program. Paste it anywhere and give us the link.

Reply

18 mahavir September 15, 2009

Awesome man!!!!!\
this really helped………..

Reply

19 Mobashir September 26, 2009

i m a new user for linux platform,may any body plz let me know how to code,compile etc a graphics application for c++ under linux platform ,,,,,( explain with example plz)

Reply

20 vaibhav October 7, 2009

it is showing that gcc command not found . so what to do help me body.

Reply

21 neeraj sinha October 7, 2009

@vaibhav!
probably gcc is not installed. Install it first depending on your linux.
and try the commands. !
http://susenj.wordpress.com

Reply

22 yash October 8, 2009

i hav c++ program in linux how i ll run it in windows c++ because it gives 25 errors

Reply

23 Shivam October 21, 2009

thx buddy it really helps me….

their is some IDE for C++ environment…

Reply

24 neeraj sinha October 22, 2009

@shivam:
yes there is: like KDevelop, Anjuta, Kate etc.

Reply

25 soumendu ganguly December 6, 2009

thanx…….
u help me lot……….

Reply

26 sagnik mukherjee February 11, 2010

THANK U….:)

Reply

27 kiran May 27, 2010

Thanks…

Reply

28 firoz July 1, 2010

how to get o/p in c program pls explain me na

Reply

29 www September 25, 2010

the output command does not do on fedora 13
#./test

Reply

30 mohammed fereja April 12, 2011

thanks..alot it just helped me out

Reply

31 sreedhar.M April 19, 2011

I am sreedhar,i am doing MCA.I have interest to learn programming languages in linux operating system.so,what should i do.

Reply

32 murali June 29, 2011

thank u

Reply

33 David July 23, 2011

ha, of course. Thanks for posting this. Saved me an embarrassing question on some IRC channel or a forum.

Reply

34 Hubert Vijay September 13, 2011

Good work dude….proves to be very useful for the begginers

Reply

35 vandana December 13, 2011

thnx…..for providin this nice solution…

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 9 + 2 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: