C & C++ On Unix

Posted byShailesh Posted onAugust 24, 2011 Comments0

Till a few years back, it was really difficult to obtain a free version of a compiler to run on ones machine to learn C or C++. And one had to resort to using a commercial compiler either by paying money and buying a licence or using a pirated copy of the same. Couple of years back, Borland C was considered to be the best compiler in the market for windows platform but later Microsoft’s Visual-C usurped it to take the most popular position. Then GNU/Linux got wider acceptance and the rest as they say is history. Most GNU/Linux distributions ship with the gcc suite of compilers. GCC stands for GNU Compiler Collection. And it contains compilers for various languages such as C,C++,Java and so on.

To check which version of gcc is installed on unix computer.
$ gcc -v

Example:- Basic c program to print “Hello Genowin Technologies”

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
printf(“Hello Genowin Technologies\n”);
printf(“\nEnd of program\n”);
return 0;
}

After writing a C program we need to compile it. Compilation is the process of converting human readable code into a form which the machine can   understand. Command to compile
$ gcc test.c

If there is no error, the program will be successfully compiled and the compiler will create an executable file called a.out. Now to run our program, we have to execute a.out executable file.

$ ./a.out
You can specify an execuable file name while compiling program itself:
$ gcc -o test test.c
Now execute test (see output of test.c)
$ ./test

Happy To Help You ….
All Linux solution & Training.
Genowin Technologies(www.genowin.com)

Category

Leave a Comment