Howto see output of C program in Linux or UNIX

Posted on in Categories , , , , , , , , last updated September 15, 2007

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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

55 comment

  1. 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.

    1. Use just have to do write ur program in gedit and save it with c extension…..
      U have to go In file right click then document then click empty document….
      Now u can write ur program this is gedit then save it filename.c extension…..

      Have…fun…..

  2. 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.

    1. 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.

Leave a Comment