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:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Facebook it - Tweet it - Print it -


{ 35 comments… read them below or add one }
yaa
you help me a lot
thnx budy
wt is the process to get output in c program
hey man thanks for the instruction…… i can now compile and run c programs……
this is realy very nice.thanks to help me.
i have installed MinGW now pls tell how to write a program and excuate it
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.
i search this site through google and find my answer on the topic … How can i run and compile program on gcc compiler?
Nice post. It helps newbie a lot.
:)
The given commands is work properly…………
it is very helpful
Thanx man!!!
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
Superb information , i liked this website very much.
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
Install gcc compiler.
@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!
I am successfully executing a C prg in Turbo C but i am getting a runtime error in gcc. Please help
@Ivneet:
Please be specific about your program. Paste it anywhere and give us the link.
Awesome man!!!!!\
this really helped………..
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)
it is showing that gcc command not found . so what to do help me body.
@vaibhav!
probably gcc is not installed. Install it first depending on your linux.
and try the commands. !
http://susenj.wordpress.com
i hav c++ program in linux how i ll run it in windows c++ because it gives 25 errors
thx buddy it really helps me….
their is some IDE for C++ environment…
@shivam:
yes there is: like KDevelop, Anjuta, Kate etc.
thanx…….
u help me lot……….
THANK U….:)
Thanks…
how to get o/p in c program pls explain me na
the output command does not do on fedora 13
#./test
thanks..alot it just helped me out
I am sreedhar,i am doing MCA.I have interest to learn programming languages in linux operating system.so,what should i do.
thank u
ha, of course. Thanks for posting this. Saved me an embarrassing question on some IRC channel or a forum.
Good work dude….proves to be very useful for the begginers
thnx…..for providin this nice solution…