Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. C++ Course

Lesson 3 of 45 · C++

Lesson 11: Arrays

Duration: 9 min

Arrays\n\nArrays provide the simplest form of contiguous storage. In C++ you can declare a static array with a compile‑time size, or you can use std::array (a thin wrapper) for better type safety and value semantics.\n\n---\n\n## Example: C‑style array vs. std::array\ncpp\n// C‑style array\nint numbers[5] = {1, 2, 3, 4, 5};\nfor (int i = 0; i < 5; ++i) {\n std::cout << numbers[i] << ' ';\n}\nstd::cout << '\\n';\n\n// std::array\nstd::array<int, 5> arr = {10, 20, 30, 40, 50};\nfor (auto v : arr) {\n std::cout << v << ' ';\n}\nstd::cout << '\\n';\n\n\nBoth representations store elements contiguously, but std::array participates in the STL ecosystem (e.g., can be passed to algorithms) and supports .size(), .front(), .back().\n\n> Tip: Use std::array whenever the size is known at compile time; reserve raw arrays for interfacing with legacy C APIs.\n\n---\n\n<Alert type="info">Array bounds are not checked by the language. Consider std::vector or std::array's at() for safe access.

Previous: Lesson 10: Function OverloadingNext: Lesson 12: C‑Style Strings and std::string