Howto see output of C program in Linux or UNIX

by on April 9, 2007 · 51 comments· LAST UPDATED September 15, 2007

in , ,

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.

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

Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 51 comments… read them below or add one }

1 ajay May 25, 2007 at 4:38 am

you help me a lot
thnx budy


2 firoz July 1, 2010 at 5:38 am

wt is the process to get output in c program


3 Shaik.moulali June 26, 2014 at 9:26 am

After written the program in c language
To Compile that program in turboc click the ALT+F9
To Run that program in turboc click the CTRL+F9


4 vivek June 4, 2007 at 6:18 pm

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


5 manisha September 15, 2007 at 11:05 am

this is realy very nice.thanks to help me.


6 umair January 22, 2008 at 5:50 pm

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


7 pinku June 2, 2008 at 10:19 am

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.


8 rakesh kumar thakur August 15, 2008 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?


9 tintin October 23, 2008 at 12:18 am

Nice post. It helps newbie a lot.


10 ashutosh February 1, 2009 at 10:21 am

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


11 Stefaan April 21, 2009 at 5:19 pm

Thanx man!!!


12 Thanks for this tip May 8, 2009 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


13 Avinash T M May 21, 2009 at 12:52 pm

Superb information , i liked this website very much.


14 bhargav July 19, 2009 at 7:23 pm

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


15 nixCraft July 19, 2009 at 8:08 pm
16 neeraj sinha July 28, 2009 at 2:30 pm

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!


17 Ivneet August 17, 2009 at 6:35 am

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


18 neeraj sinha August 18, 2009 at 4:30 pm

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


19 mahavir September 15, 2009 at 1:04 am

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


20 Mobashir September 26, 2009 at 7:27 pm

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)


21 vaibhav October 7, 2009 at 1:50 pm

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


22 neeraj sinha October 7, 2009 at 8:19 pm

probably gcc is not installed. Install it first depending on your linux.
and try the commands. !


23 yash October 8, 2009 at 3:14 am

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


24 Shivam October 21, 2009 at 2:59 pm

thx buddy it really helps me….

their is some IDE for C++ environment…


25 neeraj sinha October 22, 2009 at 3:02 am

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


26 soumendu ganguly December 6, 2009 at 3:19 am

u help me lot……….


27 sagnik mukherjee February 11, 2010 at 10:20 am



28 Hk April 27, 2010 at 9:50 am

I use Fedora 12 (live Cd).
i created a c program in it and tried to execute.
it says that no such command..
how to eliminate this problem.


29 kiran May 27, 2010 at 12:37 pm



30 firoz July 1, 2010 at 5:40 am

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


31 www September 25, 2010 at 7:45 pm

the output command does not do on fedora 13


32 hemant March 3, 2011 at 7:20 am

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


33 mohammed fereja April 12, 2011 at 9:50 am

thanks..alot it just helped me out


34 sreedhar.M April 19, 2011 at 10:26 am

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


35 murali June 29, 2011 at 3:52 am

thank u


36 David July 23, 2011 at 4:26 pm

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


37 Hubert Vijay September 13, 2011 at 10:29 pm

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


38 akshata kittur October 2, 2011 at 4:01 pm

I have typed a hello world program in fedora.. But how should i get back to the terminal.what are the keys on keyboard that i hav t press and want commands to type so that my file is saved.


39 vandana December 13, 2011 at 5:29 am

thnx…..for providin this nice solution…


40 vaishali March 30, 2012 at 4:17 am

it really helped me thanks


41 ankit senger August 6, 2012 at 9:34 am

thanks it is very helpful for me


42 kishore vignesh August 10, 2012 at 7:57 am

thank you :) !


43 lata September 11, 2012 at 4:51 am

Is gcc compiler necessary for C++ programming under Linux????
Can we do this without any compiler????


44 neeraj September 11, 2012 at 10:00 am

Any language needs a compiler/interpreter.
I can even run Turbo C++ on Linux.
so, answer to your first question = no, but yes, it’s the most preferred compiler for any *nix Operating system.
for second question = No.


45 lata September 11, 2012 at 11:24 am

thank you so much for ur help and consideration


46 sra1 September 28, 2012 at 6:55 am

thanq nd what abt html programmes


47 neeraj September 28, 2012 at 1:05 pm

Sorry, There is no programming language called HTML.
What exactly you want to do with HTML under gcc?


48 sanju November 6, 2012 at 6:56 am

hey there, can you tell me how to see the output of a c++ program in unix environment page by page ???


49 Dibya November 26, 2012 at 7:27 am

Thank Man…


50 nagababu November 28, 2012 at 6:31 am

thanks to this web site


51 George Maithya July 8, 2014 at 2:12 pm

Please show me how to write a program in c that prints a file a screenfull at a time waiting for response from user.


Leave a Comment

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

Previous Faq:

Next Faq: