Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
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

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;
}

Output

    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;
}

Output

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

    sh-4.3$ ./main
    Hello, World!





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



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 (2015-2018), Some rights reserved.