Skip to content
Justice Tech School

std::array and C Arrays

std::array has a fixed size and safe helpers. Plain arrays decay to pointers.

Example
#include <iostream>
#include <array>
#include <algorithm>

int main() {
  std::array<int, 3> a = {3, 1, 2};
  std::sort(a.begin(), a.end());
  for (int x : a) std::cout << x << " ";
  std::cout << a.size() << " " << a.at(0) << "\n";
  return 0;
}

Result

1 2 3 3 1

Exercise

Fixed size container.

std::<int, 3>

Quiz Test

Does std::array have fixed size?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.