How to Compile and Run a C program in Linux?
Compiled on Jul 29 2012 in C
Do you want to know how to code, compile and execute C Program in Linux platform? Then you are at right place. In this tutorial I will show you how to write and run C Program in Linux terminal.
How to write & save C Program In Linux Terminal ?
Step 1
Start/Open/Go to Linux Terminal and type
vi Filename.cIn the above screenshot I have given filename as tutorial.c
Step 2
The Vi Editor will open.
Press I to insert text and start writing the C Program in it.
iStep 3
After coding it.Just press Esc button and type
:wqHere :wq specifies save and exit.
How to Compile C Program in Linux Terminal?
Step 4
The next step after coding is compilation part.To compile C Program type the following in Terminal,
gcc Filename.cor
gcc -o h Filename.cIf you face any error again enter into text editor,
vi Filename.cafter fixing the error press Esc button and type
:wqStep 5
Now execute the program to see the Output type
./a.outor
./h Filename.cThe output of the program will be displayed.
To know more about commands used in VI editor checkout our next tutorial.


