Notes / C++ / Arrays

Arrays in C++ — Revision Notes

A quick-reference cheat sheet: definition, syntax, example, common mistakes and an interview tip.

beginner 📖 2 min revision

Definition

📌 Arrays C++ supports the same fixed-size arrays as C, but also offers safer alternatives from the standard library: std::array (fixed size, bounds-aware) and std::vector (dynamic size, can grow)..

Syntax

syntax
type arrayName[size] = {values};
#include <vector>
vector<type> name = {values};

Example

cpp
#include <iostream>
#include <vector>
using namespace std;

int main() {
    vector<int> scores = {90, 85, 70};
    scores.push_back(100);
    for (int s : scores) {
        cout << s << " ";
    }
    cout << endl;
    return 0;
}

Output

output90 85 70 100

Important Points

Common Mistakes

Interview Tip

🎯 Before your interview Interviewers may ask "why prefer vector over a raw array?" — dynamic sizing, automatic memory management, and built-in helper methods.
Back to notes Read full lesson →