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.c
In 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.
i
Step 3
After coding it.Just press Esc button and type
:wq
Here :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.c
or
gcc -o h Filename.c
If you face any error again enter into text editor,
vi Filename.c
after fixing the error press Esc button and type
:wq
Step 5
Now execute the program to see the Output type
./a.out
or
./h Filename.c
The output of the program will be displayed.
To know more about commands used in VI editor checkout our next tutorial.