HOW TO INSTALL C AND C++ COMPILERS IN UBUNTU

Now you need to open first.c file

sudo gedit first.c

add the following lines save and exit the file :

#include
int main ()
{
printf(“hello world”);
return 0;
}

Firstly compile the code using the following command
cc -c first.c

that would produce an object file you may need to add to the library.

then create an executable using the following command

cc -o first first.c

Now run this executable using the following command

./first

Output should show as follows

Hello, world

Compiling your first C++ program

If you want to run c++ program follow this procedure

g++ is the compiler that you must use.

you should use a .cpp file extension rather than a .c one

You need to create a file

sudo gedit first.cpp

add the following lines save and exit the file

#include
int main ()
{
std::cout << "hello world" << std::endl;
return 0;
}

Run your C++ Program using the following command

g++ first.cpp -o test

./test

Output should show as follows

Hello World


About this entry