≡ Menu

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.

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 itGoogle+ itPDF itFound an error/typo on this page?

{ 51 comments… add one }

  • ajay May 25, 2007, 4:38 am

    you help me a lot
    thnx budy

    • firoz July 1, 2010, 5:38 am

      wt is the process to get output in c program

      • Shaik.moulali June 26, 2014, 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

  • vivek June 4, 2007, 6:18 pm

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

  • manisha September 15, 2007, 11:05 am

    this is realy very nice.thanks to help me.

  • umair January 22, 2008, 5:50 pm

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

  • pinku June 2, 2008, 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.

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

  • tintin October 23, 2008, 12:18 am

    Nice post. It helps newbie a lot.

  • ashutosh February 1, 2009, 10:21 am

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

  • Stefaan April 21, 2009, 5:19 pm

    Thanx man!!!

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

  • Avinash T M May 21, 2009, 12:52 pm

    Superb information , i liked this website very much.

  • bhargav July 19, 2009, 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

  • neeraj sinha July 28, 2009, 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!

  • Ivneet August 17, 2009, 6:35 am

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

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

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

  • mahavir September 15, 2009, 1:04 am

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

  • Mobashir September 26, 2009, 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)

  • vaibhav October 7, 2009, 1:50 pm

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

  • neeraj sinha October 7, 2009, 8:19 pm

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

  • yash October 8, 2009, 3:14 am

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

  • Shivam October 21, 2009, 2:59 pm

    thx buddy it really helps me….

    their is some IDE for C++ environment…

  • neeraj sinha October 22, 2009, 3:02 am

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

  • soumendu ganguly December 6, 2009, 3:19 am

    u help me lot……….

  • sagnik mukherjee February 11, 2010, 10:20 am

    THANK U….:)

  • Hk April 27, 2010, 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.

  • kiran May 27, 2010, 12:37 pm


    • firoz July 1, 2010, 5:40 am

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

  • www September 25, 2010, 7:45 pm

    the output command does not do on fedora 13

  • hemant March 3, 2011, 7:20 am

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

  • mohammed fereja April 12, 2011, 9:50 am

    thanks..alot it just helped me out

  • sreedhar.M April 19, 2011, 10:26 am

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

  • murali June 29, 2011, 3:52 am

    thank u

  • David July 23, 2011, 4:26 pm

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

  • Hubert Vijay September 13, 2011, 10:29 pm

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

  • akshata kittur October 2, 2011, 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.

  • vandana December 13, 2011, 5:29 am

    thnx…..for providin this nice solution…

  • vaishali March 30, 2012, 4:17 am

    it really helped me thanks

  • ankit senger August 6, 2012, 9:34 am

    thanks it is very helpful for me

  • kishore vignesh August 10, 2012, 7:57 am

    thank you :) !

  • lata September 11, 2012, 4:51 am

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

    • neeraj September 11, 2012, 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.

      • lata September 11, 2012, 11:24 am

        thank you so much for ur help and consideration

  • sra1 September 28, 2012, 6:55 am

    thanq nd what abt html programmes

    • neeraj September 28, 2012, 1:05 pm

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

  • sanju November 6, 2012, 6:56 am

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

  • Dibya November 26, 2012, 7:27 am

    Thank Man…

  • nagababu November 28, 2012, 6:31 am

    thanks to this web site

  • George Maithya July 8, 2014, 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