C Tutorial

C Basics

C Data Types

C Input/Output

C Operators

C Conditional Statements

C Control Statements

C Strings

C Functions

C Arrays

C Structure and Unions

C Pointers

C Preprocessor Directives

C Command-line Arguments

C File Handlings

C Graphics

C Advance Topics

C Tips and Tricks

C Important Topics

C Practice

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!

C Language Tutorial »

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.