Environment Setup and Hello World for C Programming Linux/Unix

Hello World for C Programming Linux/Unix. Before we get our environment setup for writing our first C Program, lets talk a little about ‘Compiler’.

C program are high level program, which means its easier for us to read however, computers cannot understand them so they have to be converted down to machine readable codes. These codes are known as bite codes. A compiler does exactly that!

For C programs, we use GCC compiler. It comes in built in Linux and Unix systems, like Ubuntu(Linux) and MacOs(Unix). For windows, we may have to install the compiler itself. However, its a tedious process so we will use TurboC instead. You can download TurboC  here.

For Linux & Unix users:

Before we start compiling our programs, lets find a suitable text editor to write our codes in. Text editors are essentially just a ‘notepad’ to type our code in and save it as a text file.
For linux, we have ‘gedit’ on Ubuntu(Linux) or ‘textEdit’ on MacOs(Unix).
Fire up the text editor and copy paste the following code for hello world and save it as hello.c

#include<stdio.h>

int main()
{
    printf("Hello World");
    return 0;
}

Hello World for C Programming Linux/Unix



I saved my hello.c in home directory so that we don’t have to change directory when we open our terminal.
Fire up your terminal same way we opened up gedit.

Hello World for C Programming Linux/Unix
Hello World for C Programming Linux/Unix


Now that we located our c program, its time to compile it using the command ‘gcc hello.c’
Then it will generate an ‘a.out’ file, which has machine executable codes or bytecode.

Then just use ‘./a.out’ command to execute the bytecode.

Here we can see our output as ‘Hello World’ in the console.

Congratulations! You are now a c programmer ;).

Hello World for C Programming Linux/Unix.

For windows, the tutorials are upcoming.