If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
पिछले topics जो भी Array examples देखे थे बो सभी single dimensional array थे , इस topic में हम multidimensional Array पढ़ेंगे।
Multidimensional Array का Simply मतलब होता है : Array inside Array , C++ में हम Multidimensional Array भी create कर सकते हैं । Multidimensional Array में हम हर एक index के लिए value की जगह एक Array देते है , और फिर उस Array के अंदर हम अपनी जरूरत के हिसाब से data store करते हैं।
char letters[2][3] = { {'A', 'B', 'C'}, {'D', 'E', 'F'} };
ऊपर दिए गए example में array size 2 , 3 है मतलब , इसमें दो Array Element है जिनके अंदर 2 , 3 elements होंगे। ध्यान रहे कि multidimensional array में height और width का elements type same रहना चाहिए। आप हर Array Element का अलग अलग type नहीं दे सकते हैं।
For Example -
char letters[2][3] = { {'A', 'B'}, {1, 2, 3} };
single dimensional array की तरह ही यह भी आप index के bases पर element access कर सकते हैं। बस आपको normal element की जगह Array Element मिलेगा।
#include <iostream>
using namespace std;
int main() {
char letters[2][3] = {
{'A', 'B', 'C'},
{'D', 'E', 'F'}
};
//if we access letters[0] then we get {'A', 'B', 'C'}, so we can access it like.;
cout << "position 00 = " << letters[0][0] << endl;
cout << "position 01 = " << letters[0][1] << endl;
cout << "position 11 = " << letters[1][1] << endl;
return 0;
}
position 00 = A position 01 = B position 11 = E
इस आप row * column समझ सकते हैं , जहां first index पर आपको row और second index पर columns मिलेगा।
Column | |||
row | Index = 0:0 A | Index = 0:1 B | Index = 0:2 C |
Index = 1:0 D | Index = 1:1 E | Index = 1:2 F |
#include <iostream>
using namespace std;
int main() {
char letters[2][3] = {
{'A', 'B', 'C'},
{'D', 'E', 'F'},
};
for(int row=0; row<2; row++) {
for(int column=0; column<3; column++) {
cout << row << ":" << column << "=" << letters[row][column] << endl;
}
}
return 0;
}
0:0=A 0:1=B 0:2=C 1:0=D 1:1=E 1:2=F
I Hope, आपको C++ में multidimensional array के बारे में अच्छे से समझ आया होगा।
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook