
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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
- Related Articles
- Initialization of a multidimensional array in C
- Print Binary Tree in 2-Dimensions in C++
- How to convert Multidimensional PHP array to JavaScript array?
- How to check for multidimensional nature of an array in PHP
- Multidimensional array in Java
- What is a multidimensional array in C language?
- How To Access Different Rows Of A Multidimensional Numpy Array?
- How to do multidimensional array intersection using JavaScript?
- How do you find the number of dimensions of an array in C#?
- PHP Multidimensional Array.
- How to print size of array parameter in a function in C++?
- How to set multidimensional array into JTable with Java?
- How to print the contents of array horizontally using C#?
- MongoDB multidimensional array projection?
- Single dimensional array vs multidimensional array in JavaScript.

Advertisements