Pertanyaan dan Jawaban Wawancara Paling Populer & Tes Online
Platform edukasi untuk persiapan wawancara, tes online, tutorial, dan latihan langsung

Bangun keterampilan dengan jalur belajar terfokus, tes simulasi, dan konten siap wawancara.

WithoutBook menghadirkan pertanyaan wawancara per subjek, tes latihan online, tutorial, dan panduan perbandingan dalam satu ruang belajar yang responsif.

Chapter 2

Syntax, Data Types, Variables, Input Output, and Operators

Learn the basic building blocks of C++ programs including variables, built-in types, expressions, console I/O, and operator behavior.

Inside this chapter

  1. Basic Syntax and Variables
  2. Common Built-In Types
  3. Console Input and Output
  4. Operators and Expressions
  5. Type Conversion
  6. Real-World Usage Snapshot

Series navigation

Study the chapters in order for the clearest path from C++ basics to modern ownership, templates, concurrency, performance, and production-ready engineering practices. Use the navigation at the bottom to move smoothly through the full series.

Tutorial Home

Chapter 2

Basic Syntax and Variables

#include <iostream>

int main() {
    int age = 21;
    double salary = 45000.50;
    char grade = 'A';
    bool active = true;

    std::cout << age << '\n';
}

C++ is strongly typed and case-sensitive. Choosing meaningful variable names and correct types is one of the first important habits students should build.

Chapter 2

Common Built-In Types

Type Typical Usage
intWhole numbers
doubleFloating-point values
charSingle character
boolTrue or false conditions
std::stringText data
Chapter 2

Console Input and Output

#include <iostream>
#include <string>

int main() {
    std::string name;
    std::cout << "Enter name: ";
    std::cin >> name;
    std::cout << "Hello, " << name << '\n';
}

std::cin and std::cout are beginner-friendly standard stream interfaces. Later, students should also understand stream states, buffering, and line-based input.

Chapter 2

Operators and Expressions

C++ supports arithmetic, relational, logical, assignment, bitwise, and increment-decrement operators. Understanding precedence and side effects is important for correctness and readability.

int a = 10;
int b = 3;
int sum = a + b;
bool bigger = a > b;
int remainder = a % b;
Chapter 2

Type Conversion

double result = static_cast<double>(5) / 2;

C++ allows both implicit and explicit conversions. Beginners should learn to use explicit casts carefully when intent matters, instead of depending blindly on automatic conversion.

Chapter 2

Real-World Usage Snapshot

Every larger C++ system still depends on clean handling of types, input-output, and expressions. Sloppy basics create harder bugs later in templates, containers, concurrency, and performance-critical logic.

Hak Cipta © 2026, WithoutBook.