How To Compile and Run C
How To Compile and Run C
10
Ubuntu 11.10 (Oneiric Ocelot) is one of the most popular operating system for programming
because there are lot of great open source applications, tools, compilers, debuggers, IDEs
(Integrated Development Environment ) are available free of cost. Some of them are - GCC –
The greatest compiler for C language (from FSF (‘Free Software Foundation’ by Stallman);
Linux Torwalds used GCC while developing Linux Kernel), Eclipse IDE (The most popular
‘Integrated Development Environment’ for Java programmers), Netbeans, KDevelop, Codelite
etc.
C/C++ language is a high level programming language (although the term high and low is used
in relative sense e.g C is a high level language as compared to Assembly but if we compare it
with java then C is a low level programming language; the term high or low basically describes
the closeness with hardware). Most of the operating systems has been written in C language.
This post has been written for beginners who just started learning C/C++ or the programmers
who have migrated from Windows to Ubuntu (although the commands are almost same for all
Linux based operating system).
#include<stdio.h>
void main()
{
printf("Hello! This is my first C program with Ubuntu 11.10\n");
/* Do something more if you want */
}
GCC (GNU Compiler Collection) is installed by default, in Ubuntu. To compile the program,
open the terminal and move on to the target directory type the command – (where gcc implies
compiler name, then it asks for the file name of the source program while -o option specifies
the file name of the output program)
If there is no syntax/semantic error in you program then the compiler will successfully generate
an executable file, otherwise fix the problem in your code.
./hello1
The steps are almost same as above but you need to install g++ compiler, the file extension
should be .cpp and in compilation phase replace gcc with g++. To install G++ compiler, execute
the command -