The C++ Standard Library
- C++ Library - <valarray>
- C++ Library - <utility>
- C++ Library - <typeinfo>
- C++ Library - <tuple>
- C++ Library - <thread>
- C++ Library - <string>
- C++ Library - <stdexcept>
- C++ Library - <regex>
- C++ Library - <numeric>
- C++ Library - <new>
- C++ Library - <memory>
- C++ Library - <locale>
- C++ Library - <limits>
- C++ Library - <functional>
- C++ Library - <exception>
- C++ Library - <complex>
- C++ Library - <atomic>
- C++ Library - <streambuf>
- C++ Library - <sstream>
- C++ Library - <ostream>
- C++ Library - <istream>
- C++ Library - <iostream>
- C++ Library - <iosfwd>
- C++ Library - <ios>
- C++ Library - <iomanip>
- C++ Library - <fstream>
- C++ Library - Home
The C++ STL Library
- C++ Library - <iterator>
- C++ Library - <algorithm>
- C++ Library - <vector>
- C++ Library - <unordered_set>
- C++ Library - <unordered_map>
- C++ Library - <stack>
- C++ Library - <set>
- C++ Library - <queue>
- C++ Library - <map>
- C++ Library - <list>
- C++ Library - <forward_list>
- C++ Library - <deque>
- C++ Library - <bitset>
- C++ Library - <array>
C++ Programming Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
C++ Library - <array>
Introduction
Arrays are sequence container of fixed size. Container is a objects that holds data of same type. Sequence containers store elements strictly in pnear sequence.
The container class uses imppcit constructor to allocate required memory statically. Memory is allocated at the compile time, hence array size cannot shrink or expand at runtime. All elements inside array are located at contiguous memory locations.
Definition
Below is definition of std::array from <array> header file.
template < class T, size_t N > class array;
Parameters
T − Type of the element contained.
T may be substituted by any other data type including user-defined type.
N − Size of the array.
Zero sized arrays are also vapd. In that case array.begin() and array.end() points to same location. But behavior of calpng front() or back() is undefined.
Member types
Following member types can be used as parameters or return type by member functions.
Sr.No. | Member types | Definition |
---|---|---|
1 | value_type | T (First parameter of the template) |
2 | reference | value_type& |
3 | const_reference | const value_type& |
4 | pointer | value_type* |
5 | const_pointer | const value_type* |
6 | iterator | a random access iterator to value_type |
7 | const_iterator | a random access iterator to const value_type |
8 | reverse_iterator | std::reverse_iterator <iterator> |
9 | const_reverse_iterator | std::reverse_iterator <const_iterator> |
10 | size_type | size_t |
11 | difference_type | ptrdiff_t |
Functions from <array>
Below is pst of all methods from <array> header.
Member functions
Sr.No. | Method & Description |
---|---|
1 | Returns a reference to the element present at location N in given array container. |
2 | Returns a reference to the last element of the array container. |
3 | Returns an iterator which points to the start of the array. |
4 | Returns a constant iterator which points to the start of the array. |
5 | Returns a constant iterator which points to the past-end element of array. |
6 | Returns a constant reverse iterator pointing to the last element of the array. |
7 | Returns a constant reverse iterator which points to the past-end. |
8 | Return a pointer pointing to the first element of the array container. |
9 | Tests whether size of array is zero or not. |
10 | Returns an iterator which points to the past-end element of array. |
11 | Sets given value to all elements of array. |
12 | Returns a reference to the first element of the array container. |
13 | Returns the maximum number of elements that can be held by array container. |
14 | Returns a reference to the element present at location N in a given array container. |
15 | Returns a reverse iterator pointing to the last element of the array. |
16 | Returns a reverse iterator which points to the theoretical element preceding to first element of the array. |
17 | Returns the number of elements present in the array. |
18 | Swap the contents of the two array. |
Non-member overloaded functions
Sr.No. | Method & Description |
---|---|
1 | Returns reference to the Ith element of the array container. |
2 | Tests whether two containers are identical or not |
3 | Tests whether two containers are identical or not |
4 | Tests whether first array container is less than second or not. |
5 | Tests whether first array container is less than or equal to second or not. |
6 | Tests whether first array container is greater than second or not. |
7 | Tests whether first array container is greater than or equal to second or not. |
Non-member specipzation functions
Sr.No. | Method & Description |
---|---|
1 | Provides compile-type indexed access to the type of the elements of the array using tuple-pke interface. |
2 | Returns the total number of elements present in the container. |