Strings, Containers and Memory

std::array

How std::array gives fixed size arrays a safer interface.

How Do I Define an Array?

Learn how to define an array in C++ using C-style syntax or std::array, with examples of sizes, initializers and a common mistake to watch out for.

2 min read

What Is get() in C?

C has no get() function for arrays. In C++, get() means std::get, which reads one std::array element by a fixed, compile-time index. Examples follow below.

2 min read

What Is std::array in C++?

std::array is a container from the <array> header, added in C++11. It stores a fixed number of same-typed elements, shown in a short example.

1 min read

Related topics

More in strings, containers and memory

String Methods The main std::string member functions and how C strings work. Finding in Strings How to use find() to locate characters and substrings in a string. String Contains How to check whether a string holds a substring, plus the C string.h library. Comparing Strings How to compare strings in C++ and C, including strcmp and the == operator. Concatenating Strings How to join strings together in C++ and what concatenation means. Reversing Strings How to reverse a string with std::reverse and why strrev often fails. Iterating Over Strings How to loop through the characters of a string and other basic string operations. Splitting Strings How to split a string on a delimiter in C++, compared with split() in C# and Python. stringstream How stringstream, getline and the stream classes parse and build strings. Reading String Input How to read text input in C++ and related functions like strstr. Switching on Strings Workarounds for using strings in a switch, plus switch basics in C. String to Int How to turn a string into an integer with stoi, atoi and similar tools. Int to String How to turn numbers into strings and convert C strings to std::string. Char to Int How to convert a char to an int, how big a char is and how to_string helps. Vector Initialization Ways to create and fill a std::vector, and how size and resize work. Dynamic Arrays and Linked Lists Using std::vector as an ArrayList and how linked lists differ from arrays. std::list How the std::list container works and what the std:: prefix means. List vs Array When to pick a list or an array, with comparisons from C# and Python. Dictionaries with std::map How std::map works as a dictionary and the main data structures in C. Hash Sets How std::unordered_set works and how hash sets compare with maps and lists. std::set How std::set keeps unique sorted values, with a note on sets in Python. Tuples How std::tuple groups values and how tuples compare with lists in Python. std::optional How std::optional represents a value that may be missing. Returning Arrays Ways to return an array from a C++ function and how char arrays and pointers differ. Passing Arrays How arrays are passed to functions and what actually gets passed. Arrays of Structs How to store structs in an array and how structs and arrays differ. Random Numbers How to generate random numbers in C++ and the limits of rand and srand. NULL vs nullptr Why C++ added nullptr, how it differs from NULL and 0 and what null pointers are. Heap vs Stack How stack and heap memory differ and where your variables live. Segmentation Faults What causes a segmentation fault and what SIGSEGV means. Modifiable Lvalue Error What lvalues are and how to fix the expression must be a modifiable lvalue error. Valgrind and Memory Leaks How to find memory leaks with Valgrind and set up a program for GDB.