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++
- Initialization of a multidimensional arrays in C/C++
- Multidimensional Pointer Arithmetic in C/C++
- C++ Program to print an Array using Recursion
- How to print size of array parameter in C++?
- How to Read and Print an Integer value in C++
- Print "Even" or "Odd" without using conditional statement
- Print Hello World without semicolon in C/C++
- C++ program to print all Even and Odd numbers from 1 to N
- Condition To Print "HelloWord"
- How will you print numbers from 1 to 100 without using loop?
- Print calendar for a given year in C++
- Print 1 to 100 in C++, without loop and recursion
- Program to print last 10 lines
- Print system time in C++ (3 different ways)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.