Introduction to C++
Getting started with C++ programming — compiler setup, basic syntax, variables, and your first program.
Introduction to C++
C++ is a powerful, high-performance programming language widely used in systems programming, game development, embedded systems, and competitive programming.
Your First Program
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
Variables and Types
C++ is a statically typed language:
int age = 25; // Integer
double pi = 3.14159; // Double precision float
char grade = 'A'; // Character
bool isActive = true; // Boolean
std::string name = "Alice"; // String (requires <string>)
Input/Output
#include <iostream>
#include <string>
int main() {
std::string name;
int age;
std::cout << "Enter your name: ";
std::getline(std::cin, name);
std::cout << "Enter your age: ";
std::cin >> age;
std::cout << "Hello, " << name << "! You are " << age << "." << std::endl;
return 0;
}
Compilation
# Compile with g++
g++ -std=c++17 -o program main.cpp
# Run
./program
Key Differences from Python
| Feature | C++ | Python |
|---|---|---|
| Typing | Static | Dynamic |
| Compilation | Compiled | Interpreted |
| Memory | Manual/RAII | Garbage Collected |
| Speed | Very Fast | Slower |
| Syntax | Verbose | Concise |
Related Articles
🐍 python
Variables and Data Types
Learn about Python variables, data types, type casting, and dynamic typing. A comprehensive guide for beginners.
⚡ cpp
STL Vectors
A complete guide to std::vector — the most commonly used container in the C++ Standard Template Library.
🐍 python
Loops in Python
Master for loops, while loops, loop control statements, and advanced iteration patterns in Python.