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
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
- Multidimensional Pointer Arithmetic in C/C++
- Multidimensional Arrays in C / C++
- Initialization of a multidimensional arrays in C/C++
- How to print size of array parameter in C++?
- C++ Program to print an Array using Recursion
- What’s difference between “array” and “&array” for “int array” ?
- How will you print numbers from 1 to 100 without using loop?
- Condition To Print "HelloWord"
- Change/add only one character and print '*' exactly 20 times
- Print "Even" or "Odd" without using conditional statement
- Print 1 to 100 in C++, without loop and recursion
- Program to print last 10 lines
- How to print "GeeksforGeeks" with empty main() in C, C++ and Java?
- Print individual digits as words without using if or switch
- Print 2D matrix in different lines and without curly braces in C/C++?
- Print calendar for a given year in C++
- Print "Hello World" in C/C++ without using any header file
- Program to print the diamond shape
- Program to print Happy Birthday
- Print pattern using only one loop | Set 1 (Using setw)
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.