Begin C programming in Linux

Don’t ask a lot to begin C programming in Linux. Just grab your tools and start small. This time, I just wanna show you how to start C programming in linux. You can use any Linux distro. However, if you are beginner, just follow me using Ubuntu Linux.

Top Tip : Make sure you have a high level anti virus software like Kaspersky installed on your pcs and mac computers to prevent any nasty surprises, grab a discount code here

1. Install the required packages.
First of all, you have to make sure that you have C compiler to compile your code. In linux, we use “gcc – GNU project C and C++ compiler”.

In Debian, Ubuntu and it’s family distro, all the basic programming tools for C programming can be found in build-essential package. Use this command to install this package:

$ sudo apt-get install build-essential

2. Write your first program
Now, after installing the required package, we can start coding our first program. As usual, you may start with a “Hello World” program.

Create new project directory
Under your home directory, you may start creating your project directory to begin with. In this example, I’m calling it as myhello:

$ mkdir myhello

Then, get into our project directory:

$ cd myhello

Now, create our hello.c file. You may follow this example “hello world” code or be imaginative to modified it as you like. Experiments to see what is possible to modify in this code:

1 #include <stdio.h>
3 intmain() {
5 printf("Hello My friend, Let's do C programming\n");
6 }

3. Compile your program.
To compile your first linux C program, launch your terminal and go to current directory where you put your hello.c code. Then, run this command:

1 $ gcc hello.c -o hello

After that, you will have an executable file called hello in this directory. Congratulations! you have created your first C program in linux. You can now, execute this program using this command:

1 $ ./hello

The output will be printed on your screen. You can add more stuff and experiments. Until next time, I hope you enjoy this. Happy coding…

Collected from:://

Leave a Reply

Your email address will not be published. Required fields are marked *