In our today's article we discuss about how we can run C and C++ programs in Kali Linux system.
Sometimes we counter with C and C++ programs, now we are using Kali Linux as primary installation then how to run them?Well this is very easy. This tutorial is also going to be useful for other Debian based distributions like Ubuntu, Mint etc.
Without wasting valuable time let's get started.
Running C Programs in Kali Linux
First we need to have a C program in our Kali Linux system. Let's write it.
To write a C program we choose notepad++ in our Kali Linux system. Oh it's not comes with Kali Linux (Notepad++ supports Windows only) but we shows how we have installed Windows programs in Kali Linux.
After opening Notepad++ we wrote a simple 'hello world' script on C and save it with hello-world.c name on our desktop, as we can see in the following screenshot:
Now we just need to open our Terminal window in Kali Linux system and navigate to our Desktop directory by using cd command:
To run any C programs we need to have GCC in our Linux system. GCC is a C compiler for Linux or UNIX based system. It's comes pre-installed with Kali Linux but if we need to install or update gcc we can run following command in our terminal:
The screenshot of the command is following:
Let we are going to run our C program by using following command:
It will run as we can see in the following screenshot:
After running this command we can't see nothing output. No worry, it is not given any output now but created a a.out file in our current directory. We can see it by using ls command:
In the above screenshot we can see the a.out file. This is an executable file for Mac or Linux. If we use GCC in Windows system then it will create a exe file.
Now as we know this a.out file is executable we can execute this by using following command:
The screenshot is following. Here we successfully run our C program.
If we need we can do with another name using -o flag. If we need the output called 'hello' in the place of 'a.out' then we can use following command:
Then we got a file called hello and we run it using ./hello command.
Here we learned how we can run C programs in Kali Linux system.
Running C++ Programs in Kali Linux
Running C++ programming in Kali Linux is very similar to run C programs. Here in the place of GCC we need to use G++ compiler. To install/update G++ in our Kali Linux we ca use following command:
Then we can compile a C++ program. We have a C++ program ("Hello World!" file named hello.cpp for example).
Using G++ is very similar to GCC we can use -o flag to create another named file instead 'a.out'.
Then we can use following command to run our compiled file and get the output.
As we can see in the following screenshot:
This is how we can run C++ program in our Kali Linux system. In this article we learned how we can run C and C++ programs in our Kali Linux or any other Linux distributation. Hope this article helps our fellow Kali Linux users. Really love our articles? Make sure to follow us to get all our articles directly on notification. We are also available on Twitter and GitHub, we post article updates there. To join our KaliLinuxIn family, join our Whatsapp Channel & Telegram Group. We are trying to build a community for Linux and Cybersecurity. For anything we always happy to help everyone on the comment section. As we know our comment section is always open to everyone. We read each and every comment and we always reply