HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to C++VariablesData TypesOperatorsStringsVectors (vector)Conditions (if / switch)Loops (for / while)FunctionsClasses (OOP)
REFERENCE
📖 Overview
🖥️ Output & Input
📦 Variables
🔢 Numbers & Math
✍️ String
📋 Array & Vector
Arrayvector
🔁 Condition & Loop
🧩 Function & Class
C++›REFERENCE›Array & Vector
📋

Array & Vector

Fixed arrays and flexible vectors.

CommandDescription
ArrayFixed-size collection of elements.
vectorFlexible (resizable) array.

Array

Try it yourself →

Fixed-size collection of elements.

Syntax

type name[size] = {...};

Description

Arrays have a fixed size. Elements are accessed with 0-based indexing.

Example

#include <iostream>
using namespace std;
int main() {
    int numbers[3] = {10, 20, 30};
    cout << numbers[0] << endl;
    return 0;
}

Expected output

10

When to use?

Fixed number of values.

vector

Try it yourself →

Flexible (resizable) array.

Syntax

vector<Type> name = {...};

Description

push_back adds an item, size() gives the size, accessed with []. Requires <vector>.

Example

#include <iostream>
#include <vector>
using namespace std;
int main() {
    vector<int> v = {1, 2};
    v.push_back(3);
    cout << v.size() << " " << v[0] << endl;
    return 0;
}

Expected output

3 1

When to use?

Growing lists.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code