How to Run C, C++ Program in Linux, Ubuntu

How to run C, C++ program in Linux, Ubuntu. This question is asked by a reader on my Facebook page. He started using Ubuntu and written C program but he didn’t know how to compile and run this program.

In this post, I’ll show how to create, compile and run  C, C++ Pprogram in Linux, Ubuntu.

How to Run C, C++ Program in Linux, Ubuntu

1. To run a C program in Linux  we first need to install Build essential package. Build essential package install development libraries require for compilation.

Subscribe Our Tutorials

Get Latest Updates on Facebook

In Ubuntu, we install packages through the apt-get package manager. If you are not familiar with apt-get then read my previous tutorial on a apt-get package manager.

After installation check GCC version by typing.

2. Let’s create a simple c program then we compile and run this program. To create a C program I am using vi editor. You can use any editor of your choice. Create and save this program. In next step, we compile this program.

Vi, Vim editor commands

In vi editor, we use wq command for save and exit.  Type wq once your program is completed.

3. Now compile this program.

5. Once it compiles successfully,  then you can execute this program using a.out .

How to Run C++ program in Linux

To compile and run C++ code, use following command.

filename.c is the name of my C++ code file. Execute this file, once it compiles successfully.

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , . Bookmark the permalink.