Difference between GCC and G++ in C++

This post tells about the difference between GCC and G++. To begin with, they are the compilers that are used to compile and execute various C and C++ programs.

Lets’s start by talking about GCC. The GCC is the short for GNU Compiler Collection. It is a collection of compilers needed for languages like C++, C, C#, Java. GCC was made by Richard Stallman as part of the GNU project.
The main and simple difference is that GCC is used to compile the C codes, while G++ is used to compile C++ codes. But, we must also know that G++ can compile C codes too. A single line command to compile them will be:

  1. For C -       gcc program.c -o binary
  2. For C++ -     g++  program.cpp  -o binary

This was the commands to compile the files. Now, let us see how we can execute a C and C++ codes through them.

GCC compilation for C program

#include <stdio.h>
 
int main()
{
    printf("This is a C program \n");
 
    return 0;
}
  This is a C program
  ....Process exited after 1.3s

G++ compilation for C++ program

#include <iostream>
 
using namespace std;
 
int main()
{
   cout << "This is a C++ program" << endl; 
    
   return 0;
}
This is a C++ program
....Process exited after 1.7s

Also read: list of objects vs list of pointers in C++

Leave a Reply