Home » C programming

What is the difference between gcc and g++ in Linux?

Difference between gcc and g++

Both are the compilers in Linux to compile and run C and C++ programs. Initially gcc was the GNU C Compiler but now a day's GCC (GNU Compiler Collections) provides many compilers, two are: gcc and g++.

gcc is used to compile C program while g++ is used to compile C++ program. Since, a C program can also be compile complied through g++, because it is the extended or we can say advance compiler for C programming language.

Compiler command to compile C program through gcc

gcc  program.c  -o binary

program.c is the C source file name and binary is the name of binary (object file) that will be executed.

Compiler command to compile C++ program through g++

g++  program.cpp  -o binary

program.cpp is the C++ source file name and binary is the name of binary (object file) that will be executed.

C Example (main.c) - Compile, Run through gcc

/* main.c */
#include <stdio.h>
int main()
    printf("Hello, World!\n");
    return 0;


    sh-4.3$ gcc main.c -o main

    sh-4.3$ ./main
    Hello, World!

C++ Example (main.cpp) - Compile, Run through g++

/* main.cpp */
#include <iostream>
using namespace std;
int main()
   cout << "Hello World" << endl; 
   return 0;


    sh-4.3$ g++ main.cpp -o main

    sh-4.3$ ./main
    Hello, World!

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.