What is the difference between g++ and gcc?

CC++Server Side Programming

g++

GNU C++ Compiler ( g++ ) is a compiler in Linux which is used to compile C++ programs. It compiles both files with extension .c and .cpp as C++ files.

The following is the compiler command to compile C++ program.

g++ program.cpp -o filename

Here,

filename − The name of file with .c or .cpp extension.

The following is an example of using g++ compiler.

Example

 Live Demo

#include <iostream>
using namespace std;
int main() {
   int a = 20;
   cout << "The value of a : " << a;
   return 0;
}

Output

$g++ -o main *.cpp
$main
The value of a : 20

gcc

GNU C Compiler ( gcc ) is a compiler in Linux which is used to compile C programs. It compiles files with extension “.c”.

The following is the compiler command to compile C program.

gcc program.c -o filename

Here,

filename − The name of file with .c extension.

The following is an example of using gcc compiler.

Example

 Live Demo

#include <stdio.h>
int main() {
   int a = 20;
   printf("The value of a : %d", a);
   return 0;
}

Output

$gcc -o main *.c
$main
The value of a : 20
raja
Updated on 26-Jun-2020 09:21:24

Advertisements