C++ : Array in hindi , what is array in c++ language with program , Array Initial examples in hindi

what is array in c++ language with program , Array Initial examples in hindi , C++ : Array in hindi :-
इससे पहले के article मे ,C++ के fundamental data type (integer , character , float आदि ) को discuss किया है | आब इस article मे , C++ के compound data type मे से array को discuss करेगे |
Compound data type
Compound data type एक एसे data type होते है जिसमे दो या दो अधिक values store होती है | ये दो प्रकार के होते है :
Array
Array एक एस data type है जो की एक जैसे data type की बहुत सारी values को hold करता है |
Structure
Structure एक एस data type है जिसमे दो दो या से अलग अलग data type की values store होती है |
इस article मे , array को discuss करेगे |
 
Array
Array एक data type है जिसमे एक सामान data type के बहुत सारी values store होती है | इसका syntax होता है :
data type array_name[size];
यहा पर
data type : ये array मे store होने वाले value के data type को define करता है |
array_name : ये array का नाम है जिससे array को प्रोग्राम मे use किया जाता है |
size : ये array द्वारा hold किये जाने वाली value की सख्या है |
उदाहरण के लिए :
#include<iostram.h>
#include<conio.h>
void main()
{
using namesapce std;
int a[2];
a[1]=12;
a[2]=24;
cout<<“value of a[1] : “<<a[1]<<endl;
cout<<“value of a[2] : “<<a[2]<<endl;
getch();
}
इस statement int a[2]; मे , एक array बनती है जिसमे integer type की दो values hold सकती है | अतः array ‘a’ के index ‘1’ पर 12 hold होगा और index ‘2’ पर 24 assign होगा |
इसमें ‘a’ array का नाम है और ‘2’ array की size है |size की value हमेशा integer constant होता है | या एक constant expression भी हो सकती है जैसे
8 * sizeof(int);
इस expression से एक integer type के size के आठ गुना size declare होगी |
a[1] का मतलब array के first position के memory space को access होगा | और a[2] का मतलब array के second position के memory location को access किया जाता है |

Why a array is compound data type
array एक compound data type इसलिए है क्योकि array किसी fundamental data type से किसी दुसरे data type को बनता है | अतः इस array को एक data type की तरह use किया जाता है | उदाहरण के लिए :
array of char : char name[10] ,यहा पर name एक नया data type है जो की name को hold करेगा |

Index / Subscript
array मे index का बहुत महत्व है |array की value को access या array द्वारा दी गयी memory location को access कर्ण एके लिए index / Subscript को use किया जाता है |C++ मे index मे ‘0’ से start होती है |array name bracket का use index को define करने के लिए किया जाता है |

array का उदाहरन :
#include<conio.h>
#include<iostream.h>
void main ()
{
using namespace std;
int a[3];
a[0]=12;
a[1]=23;
a[2]=65;
int b [3] = {120,230,340};
cout<<“Total Strike value :”<<a[0]+a[1]+a[2]<<endl;
cout<< “Box with “<<a[0]<<strike<<“cost”<<b[0]<<endl;
cout<< “Box with “<<a[1]<<strike<<“cost”<<b[1]<<endl;
cout<< “Box with “<<a[2]<<strike<<“cost”<<b[2]<<endl;
cout<<“Size of array element a[0]  : “<< sizeof a[0]<<endl;
cout<<“Size of array ‘a’ : “<< sizeof a << endl;
getch();
}

इस उदहारण मे , दो array को use किया है
पहली array strike की सख्या को assign किजा जाता है | और दुसरे array मे boxs की cost को assign किया जाता है | cout statements से array की value को display किया जाता है |
इसके अलावा sizeof a[0] से array ‘a’ के element की size को calculate किया जाता है और sizeof a का use array की size को calculate करने के लिए किया जाता है |

इसका आउटपुट होगा :
Total Strike value :
Box with 12 cost 120
Box with 23 cost 230
Box with 65 cost 340
Size of array element a[0]  : 2
Size of array ‘a’ : 6

Array Initial
C++ मे array को initial करने के लिए अलग अलग तरीके होते है | Initial , array को define कर्ण एके बाद किया जाता है | नीचे दिए गये तरीके निन्म है :
int a[4]={12,23,45,65};
int b[4];
b[4]={4,5,6,7};
a=b;

Initial को दो तरीके से initial करते है |
1.Partially
जब array के केवल कुछ value को initial किया जाता है इसे Partially initial array कहते है | complier , array के बाकि elements को ‘0’ को assign करता है | इस तरीके से बहुत बड़ी array को initial सरलता से initial किया जाता है |
इस तरह initial करने के लिए केवल एक value को initial ‘0’ किया जाता है

int a[500] = {0};
इस उदाहरण से array ‘a’ के सभी index ‘0’ से initial हो जाएगी |

जब array declaration मे [] को blank है और इस array को initail किए  जाता है तब इस syntax से array के values को count किया जाता है |

उदाहरण के लिए

int a [] = { 1,2,3,4};

इस syntax से  array की size ‘4’ count होगी |

c++ मे array के alternative के तरह vector template class को use किया जा रखता है | इससे आगे class topic मे discuss करेगे |

इस article मे array को discuss किया गया है |आब आगे वाले article मे string और structure को discuss करेगे