C++ - Array


Advertisements

Previous Page Next Page

C++ arrays

arrays are one of the most common data types in C++. It is used for storing text. It can be created by enclosing characters in double quotation marks. It can be assigned to a variable using = sign.

array Myarray = "Hello World!";

Access character of a array

A character (also called element) of a array can be accessed with it's index number. In C++, index number starts with 0 in forward direction. The below figure and example describe the indexing concept of a array.

C++ - Array Functions

Capacity

FunctionsDescription
empty() Checks whether the array is empty or not.
size() Returns the length of the array in terms of bytes.
max_size() Returns the maximum length of the array.

Element Access

FunctionsDescription
back() Access last element of the array.
front() Access first element of the array.

Iterators

FunctionsDescription
begin() Returns iterator pointing to the first element of the array.
end() Returns iterator pointing to the past-the-last element of the array.
rbegin() Returns reverse iterator to the last element of the array.
rend() Returns reverse iterator to the element preceding the first element of the array.
cbegin() Returns const_iterator pointing to the first element of the array.
cend() Returns const_iterator pointing to the past-the-last element of the array.
crbegin() Returns const_reverse_iterator to the last element of the array.
crend() Returns const_reverse_iterator to the element preceding the first element of the array.

Previous Page Next Page
Advertisements