Tutorials Logic
Tutorials Logic, IN info@tutorialslogic.com
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Website Development
Practice
Quiz Challenge Interview Questions Certification Practice
Tools
Online Compiler JSON Formatter Regex Tester CSS Unit Converter Color Picker
Compiler Tools

C++ Setup — Install GCC and Run First Program

What is C++?

C++ is a general-purpose, compiled, statically-typed programming language created by Bjarne Stroustrup in 1979 at Bell Labs as an extension of C. It adds object-oriented programming, generic programming (templates), and the Standard Template Library (STL) on top of C's procedural foundation.

C++ is used in operating systems, game engines, browsers, databases, embedded systems, and high-frequency trading - anywhere performance and control matter.

Why Learn C++?

  • Combines low-level memory control (like C) with high-level OOP abstractions
  • Powers game engines (Unreal Engine), browsers (Chrome), and databases (MySQL)
  • Foundation for understanding how languages like Java and C# work under the hood
  • Essential for competitive programming and systems programming
  • Modern C++ (C++11/14/17/20) is expressive and safe while remaining fast

Setting Up the Compiler

PlatformCompilerInstallVerify
WindowsGCC (MinGW-w64)mingw-w64.org or via VS Code C++ extensiong++ --version
LinuxGCCsudo apt install g++g++ --version
macOSClang (via Xcode)xcode-select --installg++ --version

Structure of a C++ Program

  • #include <iostream> - includes the standard I/O library
  • using namespace std; - avoids writing std:: prefix everywhere
  • int main() - entry point of every C++ program
  • cout << - outputs to console (C++ stream syntax)
  • return 0; - signals successful execution
Hello World - First C++ Program
#include <iostream>   // standard input/output stream library
using namespace std;  // use std namespace - avoids std::cout

int main() {
    cout << "Hello, World!" << endl;  // endl = newline + flush
    cout << "Welcome to C++!" << "\n"; // \n is faster than endl
    return 0;  // 0 = success
}

Compile and Run

StepCommandDescription
Compileg++ hello.cpp -o helloCompile to executable named hello
Compile (C++17)g++ -std=c++17 hello.cpp -o helloUse C++17 standard
Run (Linux/Mac)./helloRun the program
Run (Windows)hello.exeRun on Windows
With warningsg++ -Wall -Wextra hello.cpp -o helloEnable all warnings (recommended)
C++ vs C - Key Differences
#include <iostream>
#include <string>   // C++ string class (not char array)
using namespace std;

int main() {
    // C++ uses cin/cout instead of scanf/printf
    string name;
    cout << "Enter your name: ";
    cin  >> name;
    cout << "Hello, " << name << "!" << endl;

    // C++ has bool type natively
    bool isLearning = true;
    cout << "Learning C++: " << boolalpha << isLearning << endl;

    // C++ supports // single-line comments (C99 also does)
    /* and multi-line comments */

    // C++ has references (C does not)
    int x = 10;
    int &ref = x;  // ref is an alias for x
    ref = 20;
    cout << "x = " << x << endl;  // 20

    return 0;
}

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.