1. Introduction to C++: A Comprehensive Guide with Code Examples - 2023 2. Mastering Data Types in C++: A Comprehensive Guide with Codes and Examples (2023) 3. Learn About Variables and Types of Variables in C++ | Codzify.com 4. Control Statements in C++: A Comprehensive Guide for 2023 5. C++ Tutorial: Understanding Switch Statements with Codes and Examples in 2023 6. Understanding Memory Allocation and Pointers in C++: A Beginners Guide 7. Functions in C++ 8. Call by value and Call by Reference in C++ in depth 9. Array in C++ 10. 2d arrays in C++ 11. Classes and Objects in C++ 12. Static Functions in C++ 13. Constructors and Destructors in C++ - A Complete Guide with Examples 14. Mastering Copy Constructor in C++ - Shallow vs Deep Copy with Examples | Codzify 15. Understanding Friend Functions in C++ Made Simple! 16. Inline Functions in C++ 17. this Pointer in C++ 18. Types of Inheritance in C++ 19. Polymorphism in C++ Explained with Codes and Examples in 2023 20. Templates in C++ 21. Getting the Value of a MultiMap in C++: Step-by-Step Guide with Examples 22. Multimap Find and Replace Operator in C++: Step-by-Step Guide - Codzify Topics 23. Exploring the Next_Permutation Algorithm without STL in C++ - Codzify Topics 24. C++ - The Difference Between Map and HashMap in STL 25. Updating Values in a std::multimap in C++ - Codzify Topics 26. Which data structure sorts the elements on insertion in C++ STL? 27. Can we implement Red Black Tree in c++ by STL containers? 28. How to Dynamically Declare an Array of Objects with a Constructor in C++ - A Step-by-Step Guide 29. What is the difference between a pointer and an object in C++? 30. Mastering Red-Black Trees with STLs Internal Implementation: A Step-by-Step Guide

2d arrays in C++

Article by: Manish Methani

Last Updated: October 19, 2021 at 10:04am IST
8 min 24 sec read

C++ Multi-Dimensional Arrays

MultiDimensions word itself says there will be an array with mutiple dimensions(rows and columns). The simplest form of multiple Dimensions is "Two Dimensional Array".

Syntax :-

datatype arrayName[rows][coulmns];  

Examples of Multi-Dimensional arrays

/* Two Dimensional Array */
int val = a[2][3];

/* Three Dimensional Array */
int val = a[2][3][4];

Here,
a[2][3] = 2 rows , 3 columns.
a[2][3][4] = 2 rows in outer array. Inside it 3 rows, 4 columns.

Program

#include >
using namespace std;
 
int main () {
   // an array with 3 rows and 2 columns.
   int a[3][2] = { {0,0}, {1,2}, {2,4}};
 
   // output each array element's value.                      
   for ( int i = 0; i < 3; i++ )
      for ( int j = 0; j < 2; j++ ) {
         cout << "a[" << i << "][" << j << "]: ";
         cout << a[i][j]<< endl;
      }
 
   return 0;
}

Output :-

a[0][0]: 0
a[0][1]: 0
a[1][0]: 1
a[1][1]: 2
a[2][0]: 2
a[2][1]: 4

Discover My FlutterFlow Courses and Template Apps

FlutterFlow Course: Dating App from Scratch
Learn to Create the Dating App with Admin Dashboard using No-Code Tool FlutterFlow in this comprehensive course with Clone App Access.
FlutterFlow Course: Grocery Delivery App with Admin Dashboard
Learn to Create Grocery Delivery App with Admin Dashboard using No-Code Tool FlutterFlow in this comprehensive course with Clone App Access.
FlutterFlow Course: Online Courses App from Scratch
Learn to Create an Online Courses App with Course Tracking using No-Code Tool FlutterFlow in this comprehensive course with Clone App Access.
Codzify Logo

Terms and Conditions    Cookie Policy   Refund Policy   Adsense Disclaimer

Contact: teamcodzify@gmail.com