- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to print dimensions of multidimensional array in C++
Here is a C++ program to print dimensions of given array.
Algorithm
Here template() function is used to find out the current size of array. Then recursively call it till the last dimension of array.
Example Code
#include <iostream> using namespace std; template <typename t, size_t n> void printDimensionsOfArray(const t (&a)[n]) { cout << n; } template <typename t, size_t n, size_t m> void printDimensionsOfArray(const t (&a)[n][m]) { cout << "Dimensions of the Array is: "<<n << " x "; printDimensionsOfArray(a[0]); } int main() { int a[6][7]; printDimensionsOfArray(a); return 0; }
Output
Dimensions of the Array is: 6 x 7
Advertisements