How To Compile And Run a C/C plus plus Code In Linux

ht‮//:spt‬www.lautturi.com
How To Compile And Run a C/C plus plus Code In Linux

To compile and run a C or C++ code on a Linux system, you will need a C or C++ compiler installed on your system. The most common C compiler on Linux systems is the GNU Compiler Collection (GCC), which is available by default on most Linux distributions. To install GCC on a Debian-based system (such as Ubuntu), you can use the apt-get command:

sudo apt-get install build-essential

This will install the necessary tools, including GCC, to build and compile C and C++ code on your system.

Once you have a C or C++ compiler installed on your system, you can use the gcc or g++ command to compile your code. For example, to compile a C program named hello.c, you can use the gcc command like this:

gcc hello.c -o hello

This will compile the hello.c source code into an executable file named hello.

To compile a C++ program, you can use the g++ command. For example, to compile a C++ program named hello.cpp, you can use the g++ command like this:

g++ hello.cpp -o hello

This will compile the hello.cpp source code into an executable file named hello.

Once you have compiled your code, you can run the executable file to execute your program. For example:

./hello
Created Time:2017-10-28 21:38:50  Author:lautturi