You are on page 1of 1

#1 : Write a program, better use gedit (The Default Text editor).

Right click on Desktop and create a new file fun.c and copy the code, given below and save it (C TRL+S). (C programs have the extension .c while C++ programs, have .cpp, althoug h it s a different fact that Linux doesn t recognize file based on their extension b ut some applications may do that and it also avoid confusion, so better use prop er extension) #2 : Now you compile the program using GCC compiler (I think it s installed by def ault in most versions in Ubuntu, but if it s not the case then install it by typin g sudo apt-get install gcc at terminal). Open the Terminal (CTRL+ALT+T) and type the command (First move on to the directory where your file is located, I assum e you have created the file on Desktop, If you are an absolute beginner Learn So me basic Linux Commands). cd Desktop gcc fun.c -o fun1 The -o option (specifies the Output File Name) in the following command is optio nal, but it s a good practice, because if you won t specify that then a default a.ou t file will be created (which will eventually overwrite older a.out file in that directory). #3 : Execute/Run the program. Type ./fun1 #4 : That s all. Here is one snapshot of output terminal compiling-executing-c-programCompile and Run C++ program To compile C++ program, you may need to install g++. Installing g++ compiler on Ubuntu 11.04 sudo apt-get install g++ Then all the remaining procedure is almost same. Just replace gcc by g++ from th e above tutorial and instead of a basic/simple c program, use C++ program. g++ file_name.cpp -o fun2 ./fun2

You might also like