Array Type Manipulation in C++ Last Updated : 28 May, 2017 Summarize Comments Improve Suggest changes Share Like Article Like Report This article demonstrates some of the inbuilt functions that can be used to query and manipulate array types, even a multidimensional array. These functions can be useful in cases we need information or manipulate array we initiated with different dimensions. These functions are defined in header file . Some of the functions include : is_array() : As the name suggest, the sole purpose of this function is to check if a variable is a array type or not. Notable here is that even an std::array is not considered an array according to this function. The "value" member constant returns true if type is array, else returns a false. is_same() : This function is to check Type relationships and it returns true if two types have exactly same characteristics. The "value" member constant returns true if types are same, else returns a false. CPP // C++ code to demonstrate the working of // is_array() and is_same() #include<type_traits> #include<iostream> #include<array> #include<string> using namespace std; int main() { // checking which is array using is_array cout << "Is Integer an array? : " << is_array<int>::value << endl; cout << "Is Array an array? : " << is_array<int[10]>::value << endl; cout << "Is 2D Array an array? : " << is_array<int[10][10]>::value << endl; cout << "Is String an array? : " << is_array<string>::value << endl; cout << "Is Character Array an array? : " << is_array<char[10]>::value << endl; cout << "Is Array class type an array? : " << is_array<array<int,3>>::value << endl; cout << endl; // checking for same types using is_same() cout << "Is 2D array same as 1D array? : " << is_same<int[10],int[10][10]>::value << endl; cout << "Is Character array same as Integer array? : " << is_same<int[10],char[10]>::value << endl; cout << "Is 1D array same as 1D array (Different sizes) ? : " << is_same<int[10],int[20]>::value << endl; cout << "Is 1D array same as 1D array? (Same sizes): " << is_same<int[10],int[10]>::value << endl; return 0; } Output: Is Integer an array? : 0 Is Array an array? : 1 Is 2D Array an array? : 1 Is String an array? : 0 Is Character Array an array? : 1 Is Array class type an array? : 0 Is 2D array same as 1D array? : 0 Is Character array same as Integer array? : 0 Is 1D array same as 1D array (Different sizes) ? : 0 Is 1D array same as 1D array? (Same sizes): 1 rank() : This is a property query function which returns the rank of the array. Rank means the dimension of the array. The value member constant returns the rank of object. CPP // C++ code to demonstrate the working of // rank() #include<type_traits> // for array query functions #include<iostream> using namespace std; int main() { // checking rank of different types cout << "The rank of integer is : " << rank<int>::value << endl; cout << "The rank of 1D integer array is : " << rank<int[10]>::value << endl; cout << "The rank of 2D integer array is : " << rank<int[20][10]>::value << endl; cout << "The rank of 3D integer array is : " << rank<int[20][10][40]>::value << endl; cout << "The rank of 1D character array is : " << rank<char[10]>::value << endl; cout << endl; } Output: The rank of integer is : 0 The rank of 1D integer array is : 1 The rank of 2D integer array is : 2 The rank of 3D integer array is : 3 The rank of 1D character array is : 1 extent() : Both extent and remove extent are Compound type alterations that can be applied to arrays in C++. This function returns the size of the particular dimension of array. This function takes two arguments, the array type and the dimension in whose size have to be found. This also has the member constant value for printing value. remove_extent() : This function removes the first dimension from left in the matrix/array declared. remove_all_extents() : This function removes all the dimensions of the matrix/array and converts it into base data type. CPP // C++ code to demonstrate the working of // extent(), remove_extent(), remove_all_extents() #include<type_traits> // for array query functions #include<iostream> using namespace std; int main() { // Checking extent of different types (using extent) cout << "The extent of 1st dimension of 3D integer array is : " ; cout << extent<int[20][10][40],0>::value << endl; cout << "The extent of 2nd dimension of 3D integer array is : " ; cout << extent<int[20][10][40],1>::value << endl; cout << "The extent of 3rd dimension of 3D integer array is : " ; cout << extent<int[20][10][40],2>::value << endl; cout << "The extent of 4th dimension of 3D integer array is : " ; cout << extent<int[20][10][40],3>::value << endl; cout << endl; // Removing extent of types cout << "The rank after removing 1 extent is : " ; cout << rank<remove_extent<int[20][10][30]>::type>::value << endl; // 1st dimension from left is deleted cout << "The extent of 1st after removing 1 extent is : " ; cout << extent<remove_extent<int[20][10][30]>::type>::value << endl; cout << endl; // Removing all extents of types cout << "The rank after removing all extents is : " ; cout << rank<remove_all_extents<int[20][10][30]>::type>::value << endl; // All extents are deleted cout << "The extent of 1st after removing all extents is : " ; cout << extent<remove_all_extents<int[20][10][30]>::type>::value << endl; cout << endl; } Output: The extent of 1st dimension of 3D integer array is : 20 The extent of 2nd dimension of 3D integer array is : 10 The extent of 3rd dimension of 3D integer array is : 40 The extent of 4th dimension of 3D integer array is : 0 The rank after removing 1 extent is : 2 The extent of 1st after removing 1 extent is : 10 The rank after removing all extents is : 0 The extent of 1st after removing all extents is : 0 Comment More infoAdvertise with us K kartik Follow Improve Article Tags : C++ CPP-Library cpp-array CPP Array and String Practice Tags : CPP Similar Reads C++ Programming Language C++ is a computer programming language developed by Bjarne Stroustrup as an extension of the C language. It is known for is fast speed, low level memory management and is often taught as first programming language. It provides:Hands-on application of different programming concepts.Similar syntax to 5 min read Object Oriented Programming in C++ Object Oriented Programming - As the name suggests uses objects in programming. Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism, etc. in programming. The main aim of OOP is to bind together the data and the functions that operate on them so th 5 min read 30 OOPs Interview Questions and Answers [2025 Updated] Object-oriented programming, or OOPs, is a programming paradigm that implements the concept of objects in the program. It aims to provide an easier solution to real-world problems by implementing real-world entities such as inheritance, abstraction, polymorphism, etc. in programming. OOPs concept is 15 min read Inheritance in C++ The capability of a class to derive properties and characteristics from another class is called Inheritance. Inheritance is one of the most important features of Object-Oriented Programming in C++. In this article, we will learn about inheritance in C++, its modes and types along with the informatio 10 min read Vector in C++ STL C++ vector is a dynamic array that stores collection of elements same type in contiguous memory. It has the ability to resize itself automatically when an element is inserted or deleted.Create a VectorBefore creating a vector, we must know that a vector is defined as the std::vector class template i 7 min read Templates in C++ C++ template is a powerful tool that allows you to write a generic code that can work with any data type. The idea is to simply pass the data type as a parameter so that we don't need to write the same code for different data types.For example, same sorting algorithm can work for different type, so 9 min read C++ Interview Questions and Answers (2025) C++ - the must-known and all-time favourite programming language of coders. It is still relevant as it was in the mid-80s. As a general-purpose and object-oriented programming language is extensively employed mostly every time during coding. As a result, some job roles demand individuals be fluent i 15+ min read Operator Overloading in C++ in C++, Operator overloading is a compile-time polymorphism. It is an idea of giving special meaning to an existing operator in C++ without changing its original meaning.In this article, we will further discuss about operator overloading in C++ with examples and see which operators we can or cannot 8 min read C++ Standard Template Library (STL) The C++ Standard Template Library (STL) is a set of template classes and functions that provides the implementation of common data structures and algorithms such as lists, stacks, arrays, sorting, searching, etc. It also provides the iterators and functors which makes it easier to work with algorith 9 min read C++ Classes and Objects In C++, classes and objects are the basic building block that leads to Object-Oriented programming in C++. We will learn about C++ classes, objects, look at how they work and how to implement them in our C++ program.C++ ClassesA class is a user-defined data type, which holds its own data members and 9 min read Like