How to run C and C++ programs in Kali Linux

How to run C and C++ programs in Kali Linux

January 10, 2024

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:

writing c programs in Kali Linux

Now we just need to open our Terminal window in Kali Linux system and navigate to our Desktop directory by using cd command:

cd Desktop

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:

sudo apt-get install gcc

The screenshot of the command is following:

Installing GCC in Kali Linux

Let we are going to run our C program by using following command:

gcc hello-world.c

It will run as we can see in the following screenshot:

gcc running on Kali

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:

ls
a.out in our directory

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:

./a.out

The screenshot is following. Here we successfully run our C program.

running C program in Kali Linux

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:

gcc -o hello hello-world.c

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:

sudo apt-get install g++

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’.

g++ -o hello-world hello.cpp

Then we can use following command to run our compiled file and get the output.

./hello-world

As we can see in the following screenshot:

running C++ in our Kali Linux system

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 distributationHope 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

Article posted by: https://www.kalilinux.in/2020/10/how-to-run-c-programs-in-kali-linux.html
——————————————————————————————————————–
Infocerts, 5B 306 Riverside Greens, Panvel, Raigad 410206 Maharashtra, India
Contact us – https://www.infocerts.com

This is the article generated by feed coming from KaliLinux.in and Infocerts is only displaying the content.

Open Whatsapp chat
Whatsapp Us
Chat with us for faster replies.