Create a function that prints multidimensional array size by dimenstions i.e.:
Input : int a; printDimensions(a); Output : 2x3x4 Input : int b; printDimensions(a); Output : 5x6
To solve this problem we should use template function to figure out the size of current array. Then we call this function recursively till the last dimension. For last dimension the boundary overridden template function should be used. The implementation of the idea:
Pay attention the order of two template functions. It won’t compile if you switch them.
There is one more way to get the same results by using language template features:
If you think that template names are too long to print you are not alone. There are short aliases in C++17:
std::extent_v for std::extent::value and std::rank_v for std::rank::value
- Multidimensional Arrays in C / C++
- Multidimensional Pointer Arithmetic in C/C++
- Initialization of a multidimensional arrays in C/C++
- How to print size of array parameter in C++?
- Print Hello World without semicolon in C/C++
- Print calendar for a given year in C++
- Print "Even" or "Odd" without using conditional statement
- Condition To Print "HelloWord"
- How will you print numbers from 1 to 100 without using loop?
- Program to print last 10 lines
- Print 1 to 100 in C++, without loop and recursion
- How to Read and Print an Integer value in C++
- array::front() and array::back() in C++ STL
- array::rbegin() and array::rend() in C++ STL
- array::cbegin() and array::cend() in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.