--- title: "<array> functions | Microsoft Docs" ms.custom: "" ms.date: "11/04/2016" ms.reviewer: "" ms.suite: "" ms.tgt_pltfrm: "" ms.topic: "article" f1_keywords: - "std::array::get" - "array/std::array::get" ms.assetid: e0700a33-a833-4655-8735-16e71175efc8 caps.latest.revision: 11 author: "corob-msft" ms.author: "corob" manager: "ghogen" --- # <array> functions The \ header includes two non-member functions, `get` and `swap`, that operate on `array` objects. ||| |-|-| |[get](#get_function)|[swap](#swap_function)| ## get Returns a reference to the specified element of the array. ``` template constexpr T& get(array& arr) noexcept; template constexpr const T& get(const array& arr) noexcept; template constexpr T&& get(array&& arr) noexcept; ``` ### Parameters `Index` The element offset. `T` The type of an element. `N` The number of elements in the array. `arr` The array to select from. ### Example ```cpp #include #include using namespace std; typedef array MyArray; int main() { MyArray c0 { 0, 1, 2, 3 }; // display contents " 0 1 2 3" for (const auto& e : c0) { cout << " " << e; } cout << endl; // display odd elements " 1 3" cout << " " << get<1>(c0); cout << " " << get<3>(c0) << endl; } ``` ```Output 0 1 2 3 1 3 ``` ## swap A non-member template specialization of `std::swap` that swaps two `array` objects. ``` template void swap(array& left, array& right); ``` ### Parameters `Ty` The type of an element. `N` The size of the array. `left` The first array to swap. `right` The second array to swap. ### Remarks The template function executes `left.swap(right)`. ### Example ```cpp // std__array__swap.cpp // compile with: /EHsc #include #include typedef std::array Myarray; int main() { Myarray c0 = { 0, 1, 2, 3 }; // display contents " 0 1 2 3" for (Myarray::const_iterator it = c0.begin(); it != c0.end(); ++it) std::cout << " " << *it; std::cout << std::endl; Myarray c1 = { 4, 5, 6, 7 }; c0.swap(c1); // display swapped contents " 4 5 6 7" for (Myarray::const_iterator it = c0.begin(); it != c0.end(); ++it) std::cout << " " << *it; std::cout << std::endl; swap(c0, c1); // display swapped contents " 0 1 2 3" for (Myarray::const_iterator it = c0.begin(); it != c0.end(); ++it) std::cout << " " << *it; std::cout << std::endl; return (0); } ``` ```Output 0 1 2 3 4 5 6 7 0 1 2 3 ``` ## See Also [\](../standard-library/array.md)