HOW TO COMPILE AND RUN C/C++ PROGRAMS IN UBUNTU

Compiling C/C++ programs are most easier in Linux USING TERMINAL USING COMMANDS. There is no separate software required to download on your system. Only you have to install a free Linux package called GCC, which is responsible to compile and run C/C++ program.

If you have gcc package already installed, that’s good. otherwise you can follow the following commands to install gcc on your Linux system.

$  sudo apt-get update
$  sudo apt-get install gcc

JUST ONLY 3 STEPS TO FOLLOW AND YOU GET IT!

1.Writing to program in editor

Then you have to write your C/C++ program in editor. You can choose any editor for example nano, gedit, vim etc your choice. But, for simplicity and small programs I PREFER GEDIT.

Write the code using following commands. If filename is HELLO.C then we have to type

$  gedit hello.c

then gedit application automatic opened and then you can write your c/c++ program. for example,

press CTRL + S to save and close the gedit application.

2.Compiling the program hello.c

Then you have to compile your program which you have written. make sure you have written your code correctly, otherwise gcc gives you error!

$  gcc hello -o hello.c

we write hello here to create a executable file which help us yo run our program.

3.Running the program

Now we have to run our program.

$  ./hello

THAT’S IT.

NOTE THIS THING ONLY FOR CREATING AND COMPILING THE SMALL PROGRAMS, but if you want to write a large program or YOU ARE WORKING ON A PROJECT which have large number of files inside the one single project. Then you don’t have to use gedit or any simple editors to write your program and gcc for compile your program.

In order to write and compile a large program or project of c/c++ or any type of programming language, YOU NEED A SEPARATE SOFTWARE which you can download from the Internet or Ubuntu snap store.

There are lots of Editors and IDEs for writing and compiling the code but I am telling you the best Compilers for Linux here. I highly recommend the ECLIPSE IDE FOR C/C++. It has great features and it can compile PHP, JS, Java etc languages also.

I RECOMMEND TO READ THIS How to install Eclipse in easy way for C/C++, java. java EE, PHP

SO, GOOD LUCK! DO HAPPY CODING.

I hope this article will helpful for you. <3