 Assalamu alaikum, CS201, Introduction to Computing or aaj humara lecture 16 hai. As I said earlier, it is still pointers. So lots of discussion to do with pointers. aaj hum kuch pisli discussion ko conclude karenge, pheer aage chalke hum multidimensional arrays ko par baat karenge or pheer pointers to pointers, more interesting stuff. So let's take a look at what we covered last time, or rather just conclude with a very simple example. Suppose hum ketein chaar my name aur pheer usko square brackets khali chodke samne initialize kar detein by saying equal to aur aage double quotes me hum string detein. As you know by now, what this does is it creates an array, a character array aur usko populate kar deta hai with the character string. And remember the string will be null terminated yani backslash 0 uska last character hoga. But we can do the same with a pointer as well. Suppose we say chaar star my name ptr aur pheer equal to wohi character string detein. To wohi effect achieve ho jata hai, memory mein wo string define ho jaige aur ek pointer hai my ptr, my name ptr jo usko point kar rahoga. So in dono approaches mein fark kya hai. Basic difference ye hai, as I mentioned earlier also ke jab hum ek array kreate karthein, to array ka jo naam hai woh ek constant pointer hai. Yani memory mein jo jage allocate hoti hai, uske beginning location ka address jo hai woh array ke naam mein aajaata hai aur woh reassign nahi hosakta, yani that you cannot change the location that it points to. The second example which I said was chaar pointer, chaar star my name ptr, woh jo hai woh pointer variable hai. Iswak to initialize hua hai pointing to a particular character string, lekin baad me jaake hum usko reassign kar sakte hai, hum kisi aur jage pe point kar sakte hai. So be aware that whenever we are talking of arrays, then the name can be used like a pointer, but only like a constant pointer whereas when we use a real pointer, it is a variable, we can reassign it as and when we need it. Let us move on now to multidimensional arrays. Again we will try to see ke jee, what is the relationship between the name of the array and the pointers. Suppose we have a two dimensional array, chalein character array ke dehte hai, chaar multi, chalein uska naami hum ne multi ke dee hai, kyunke we are saying it is a multidimensional array, but it is going to be two dimensions for this example. So we say chaar multi 5 10, pehle square brackets me 5, second square brackets me 10. Again we have already touched on the topic of multidimensional arrays. So you know what this means is we are declaring a character array with five rows and ten columns each. Question jo raise karta hai, wo jee ab jo iska array ka naam hai multi, wo keder point kar rahe hai, kaha pe point kar rahe hai. Single dimensional array me hum ne pishli defa bhi dekha tha, hum ne ka jee name jo hai array ka it points to the beginning location in memory jaha se aage array hum ne define kee hai, baaki jege memory kee aage padi ho, aur peh array name ke jama kar dee koi number jaha subscript kar lein toh we can move along in the array. In the case of two dimensional arrays, where does multi in this example point to? Well, if you are going to answer ke jee wo two dimensional array jo hai uski ab ye beginning, beginning means the first row and the first column, which means index zero zero usko point karta hai toh the answer would be correct, it is quite logical that it points to the beginning of the array. The only thing is that when you declare this multi dimensionally, it is easy to understand if you think about it kee jee two dimensional array memory me kese padi hui hai, kya wo isi tari kese matrix ki tara row columns me padi hui hai, no it is normally just a straight contiguous memory location starting from some address and ending somewhere else. So, it is normally pehli row, phir dosri row, phir tisri row aur wo straight line me chalte jarin. So, the addresses are only counting up. So, multi in this case is pointing to the first element of this two dimensional array, but because inside it is stored as a single row, it is still looking at the first element, which is row number zero column number zero. So, far so good. The question is, this is now the address of the zeroth element. If we were to increment multi, hum kete hai multi plus one to multi plus one kisko point karega, give it some thought before I immediately come out and give you the answer. The question is, hum ne ye character array bana hi hui hai, two dimensional array hai, multi is pointing to the beginning of the array, hum ne ka multi plus one keder point karega. Obviously, if you think about our previous talk, we said it should increment by the number of memory positions occupied by the data type of the variable, which is the array. In this case, the data type was char, normally char ek byte ya do bytes depend karta hai usko occupy karta hai. So, will this increment the memory address by that one or two bytes? Answer is no, it is very interesting. If you say multi plus one, it actually is pointing batadum, it is points to the second row ka pehla element, that is interesting. Now, something more interesting has happened that jab hum ne increment ki hai naam ke andar koi cheez jama ki hai, to it has jumped a whole row, which means jitne columns the utni memory positions jump ki hai aur pheer unki chawdai kitni hai wo data type pe depend karte hai. In this case hum ne ka char, let se char ki data type yo hai wo ek byte ke andar puri aati hai, array ke size ke andar columns hum ne ka hi hai thus. So, it will jump 10 bytes and be pointing to the 11th byte, which will be the starting point of the second row. So, when you increment the name of the array, yani kisi bhi expression me aap add kar ke usko istamal kar na chahin, to puri ki puri row aap jump kar rahin. This is exactly related to the concept ke ji. How do I increment by a certain row and a certain column? Yani agar main kahun ke ji mujhe multi me jana hai, let us say second row or third column ke andar. So, how do we do that? Not straight forward. You cannot just add plus 2 plus 3 and expect ke bahan chale jayenge plus 2 plus 3 karne se to aap row number 6 yani multi plus 5 pe chale jayenge. So, we do not want to do that. You have to understand ke ji multi ki value kya hai, wo kis cheez ko point kari hai, usko increment karein to wo kis cheez ko kahan chala jata hai aur isko dereference kese karna hai. Arrays ke hawale se dereference karna hame aata hai. Aage subscript lagaadin, square brackets ke andar 2, 3. So, it will be the third row fourth column, no problem. If we were to use pointer location, then immediately we need to say ke jisko dereference karna padega. Dereference karne ke liye haan star operator is tamal karte hain. So, next question, what does star multi mean in this case? This is a two dimensional array. In the case of the one dimensional array, star multi would have meant the value at the address pointed to by the name of the array. In this case, we said the name of the array is the starting point. Yes, it holds the address, but it is a two dimensional array. So, when I say star multi, what does it contain? What happens with star multi is that it now still contains an address. It does not contain a value yet because it is a two dimensional array. So, it contains an address and the address happens to be the address of the first row, which is the same as the starting point of the array. Yeh ni pehli row ka beginning jo location hai, that is the same as the beginning location of the entire two dimensional array. To prove this, you can simply fire up your compiler dev c plus plus or whatever you are using. Aur uske andar aap yeh karein ke jii aap declare karne array ko. Let us say, 4 multi 5 10 jishta mai ne kaha hai. Aur forend baad ko chor na karein. Aap c out istamal kartewe aap multi ki value print karein. So, you will say c out less than less than multi aur peh new line character deh din ya ndel deh tha ke nahi line peh chale jain. Uske baad aap kaheen c out less than less than star multi. Okay, and c for yourself and prove it ke ekhi jabab wo deh raha hai. Yeh ni dereference karne ke baav jood wo address hi dikhara hai aur address bhi wo hi dikhara hai jo multi me dikhara tha. So, how do we get to the element? Well, the answer by now should be obvious. Two dimensional array hai to do dereferencing ki zarurat hain. So, hame star star multi karna padega. Does that make sense? Well, it does make sense. Deh khe what you just discovered is ke star multi jo hai wo bazaate khud ek pointer hai. Multi pointer tha, but star multi is still a pointer. It points to a row, the first row in this case. So, agar hame pehle row ke pehle element ki value chahiye to pehle ush row ke pehle element ko dereference karengi ush address ko. So, we say star star multi. Then you get the value in the zeroth row, zeroth column of the array. What that means? Now, let's take a look at how do we manipulate this array? Agar hame kisi row pehle jaana ho, to multi me utni row number add karne. So, you will be jumping whole rows at a time. Once you have added that, you dereference it to make it a pointer into that row. So, suppose hame tisi row me jaana hai, to hame kate multi plus three. Multi plus three karne se you will be in fact on the fourth row of the array on the starting element. Ab main ush me agar chaute column me jaana chaat hame. To main pehle ush ko dereference karte hame. Parenthesis daal ke main ush ke bahar star laga dita hame. So, star parenthesis open, multi plus three, parenthesis closed. Aur ab isme jyotis jama karunga wo ush row ke andar number of columns paar jaayi ghi. So, chaute column ke jaane ke liye me phir plus three karunga. To ab ye fourth row, fourth column ka address aagya aur ush me agar value chahiye phir parenthesis daale aur bahar ek aur star daal ne. Gets real complicated. But look at it, star parenthesis open, star parenthesis open, multi plus three parenthesis closed, plus three parenthesis closed. Yeh lamba chawda tarika hai likhne ka multi three three. Of course, the three's are in square brackets. It does not mean ke aapko istra se two dimensional array ko handle karna chahiye. But it does make give you an alternative way of handling arrays. In this way, you can actually manipulate the entire two dimensional array by using indexing on the name of the array. Again, the way we did it last time, you could declare a variable, a pointer variable, assign to it the value of the name of the array, which means ushka beginning address aapne pointer variable me daal diya aur pointer kyunke aap variable istamaal ho rahe to usko plus plus bhi chalega, minus minus bhi chalega. You can simply increment it and step through the array. Again, as an experiment and to learn really about it, what I recommend is aap issi ko leke aage chalein iss array ko populate karlein, kisi loop ke saath populate karlein. Uske baad aap ek, let's say ke ji hum, int ki leh letin array character ki bhajai, int multi five ten karlein, issko double nested loop lagaate issko populate karlein. Let's say the values iskanda daal ne row times column. They are both integers multiplied karke array mein assign karte jaai. Having done that, now you print out the values, but print them out using a pointer. So, upar where we normally declare things, wahaane aap agar aap int star ptr karlein, which means ptr is now a pointer to an integer. Niche aake aap usko assign karlein pehle value array kii. Array name se aur phir usko increment karna churu karein and run it through a loop, number of times will be rows multiplied by columns. And if you print out the value pointed to by star ptr, which in this case, you should be sure that you dereferencing it correctly. You will be able to see ke ji pehle array ka pehla number phir dosa number phir tisa number jabdak row khatam nahi hoti aur phir next row ka pehla number. Why? Because computer ne unko ek straight line mein store kia hua hai. Yehi infact waja hai straight line storage ki ke jab aap kisi multi dimensional ya 2 dimensional array ko kisi function mein pas karte hain to aapko pehli tamam dimensions ki values deni pati hain. You can't use empty square brackets, otherwise the function won't know ke pehli row kaha khatam ho rahi aur dosi row kaha shuru ho rahi hain. It needs to know the number of columns in the array. You have to define the dimensions when you are doing a call. So, interesting stuff, but try to actually write the programs and experiment with this, ke ji double dereferencing kaise hoti hai, single dereferencing kaise hoti hai, incrementing the name of the array. It takes us to the next row and the next row and the next row. And then agar row ke baat column mein jaana hai kise add karte jaate hai. And only hands on practice will get the concepts through. What we have been talking about, now I will introduce new terminology, is actually a case of a pointer to a pointer. Do de-referencing kar rahi hai, 2 dimensional array thi. So, we said the name is actually a pointer to a pointer and then the pointer is to a data type. Ye pointers to pointers badi useful cheeze hain, but you have to be very fluent with their uses to use them correctly. The same thing can be considered in terms of arrays or pointers ko interchangeably is tamal kia. So, we can think in terms of a pointer to a pointer is like a pointer to a group of arrays, because a pointer itself can be considered an array. So, you can actually think of a new example, where we declare something which let us say character strings hain is tamal kia. Character strings ke upar ek aur interesting cheeze hain baat karte chale. Ek problem aap zaroor socha ho ka, ki jab bhi hain aay is tamal karte hain, toh pehle hain usko declare karte hain ki itni badi hogi. So, for example, agar main kahun ke aay is is tamal karte, aap apni klas ki average age nikaale. Toh apne aay is aay banali, toh uski dimension kitni rakhenge. Uske square brackets main declare karte we, kitna number deinge. Well, normally you would look around, count the students in the class and say ke ji 53 students, and you would say ke mujhe 53 kya rahe cha aayi. But, being a good programmer, you look ahead and say ke kal agar 54 ho ghi toh kya karenge. Toh ap kate hain chale, 100 se badi klas toh ni ho ghi na, toh ap age usko 100 ki dimension ke saar declare karte hain. Well, it's nice that we've looked ahead and we've tried to accommodate flexibility into the program. But, kya hi achcha hota agar hain program chalate vakt na ke likhate vakt. Chalate vakt hain kaite ke ji kitne students hain. Aur unka number leke hain memory mein uthi jage rakh lete. Well, iska tarika hain. Likin wo aaj ka topic nahi hain. Wo baadne baat hogi. Aaj ke liye hain ek shi zaroor karte hain. Wo jaha se main baat shuru ki thi, wo strings ke baare mein. Ke jab aap character strings se kisi array ko initialize karte hain. Toh jo strings ki length hoti hain wo define karte hain ki ji array ki length kya hogi. Agar toh ye single dimensional array hain. You say something like char name, empty square brackets equal to aur phir braces aur double quotation marks ke saath aap ne ek naam poora likh diya. Toh wo jitne characters hain utni lambi array ban gayi. Lekin agar hain isko change karte hain aur isko two dimensions mein leh jaain. Toh agar two dimensions mein jaain gay, toh kya array, har string ka size ek hi ho na lazmi hain or can we have different sized strings. Well, in the previous lecture we looked at an example and we said the space allocated for the array will have the same size or the same number of columns in each row. Aur phir number of characters populated wo se kum ho sakta hai chum ke ek null character bhi chai aur shayat baaki chise unused padhi ho baaki jagay. Wo aap karte ho sakta hain. Lekin jagay phir bhi wo poori ki poori row times column aap ne occupy kar li. What we are trying to do over here is try to occupy less space. Well, kitni space ki jitne lambi naam hai, koi lamba naam hai, koi chota naam hai, utni utti jagay allocate ho memory ki andar. Agar toh hain two dimensional array konventionally istamaal karenge toh koi tarika nahi hai ke hain we variable space istamaal kar sakta hain. Sab ke liye baraabar jagay allocate ho ghi hain, istamaal hain jitni marzi chahi. Lekin agar hain ek array of pointers istamaal karni. Notice what I said, array of pointers toh phir uskender aap variable jagay allocate kar sakta hain. How do we declare an array of pointers? Pahala question, can we have an array of pointers? The answer is yes, you can. You can have an array of a data type and then you can have an array of pointers. For example, agar karakter liye na hain, toh we will say something like char, star, array, square brackets. Agar square brackets maan ten likhtu, toh it will be read as array is, well let us change the name so that there is no confusion. Let us call it any other name, let us say my array. So, let us rewrite this line and say char, star, my array, square brackets ten. Isko hain padenge, my array is an array of ten pointers to character. Again, it is right to left, sirf hu joh maine pehle lafs bolin hain wo square brackets ki wajah se, ke jih it is an array of ten pointers to character. So, you can do that. Now, if main ten nikal doon. So, abhiye variable ho gaya. Iske aage wo hi braces ke saath aap initialization churu karde. Initialization churu karen ge to initialization me mai likhta hoon braces ke andar pehle likhtheton amir. So, double quotes ke andar amir comma dosi jaga me likhtheton jhangir j-e-h-a-n-g-i-r lamba naam and so on. What does it do? Pehle baale pointer ke joh point karegi jaga memory me char characters aur ek null character ki jaga reserve ho jayegi. Dursah pointer jaha pe point kar rahe hai waha pe jhangir plus null character ki joh jitni jaga joh hai wo allocate ho jayegi. Variable. Why? Because amne array me char characters nahi daale, array amari pointers ki array hai. Is construct ne kya kia amare liye? Dekin aage aap 2 dimensional array declare karte to poore row and column jitni jaga reserve ho jaati. Amne wo karne ke bajaye. We used an array of pointers and then we assigned initialize us ko kardeya with character strings jinn ki dimensions different thi. Koi choti thi, koi badi thi. Memory me utti jaga compiler joh hai reserve karte tha hai. So, am koi jaga waste nahi kar rahe. There is a huge advantage in doing things like this. Hopefully agar time hoa to ishi lecture me chalke hame ek lambe chode example ko cover karenge ya start karenge discussion uski jis kender aap is tekni ka istamaal dekhenge. For the moment ek big kya katein disclosure is about to happen. Ye joh construct hai which is an array of pointers, pehle ek chota sa aur baat karte chalun ki ji kya amne array of pointers joh hai uski andar pointers store ho saktein. Well, of course it's an array of pointers. So, agar aapke paas 3 simple pointer variables thi. Let's say p1, p2, p3 aur ek array thi of 3 pointers to un pointers p1, p2, p3 ko is array kender store bhi kiya ja sakta hai. No problem. Array of pointers is an array of pointers. You can store pointers in it. But joh raj ki main baat patane laga tha wo ye thi ke yaad hai aapko main, hain hain har program ke beginning pe hain. Aur uske aage hain, hain parentheses daalti hain aur wo aaj daak khali rahe hain. Aap hain is position me hain ke un parentheses ke andar kuch lik sakin. Kya lik hain? Let's take a look. C ke andar jab bhi program ko chalaaya jata hain. So, you can give it what we call command line arguments which means program ka naam lik hain aur uske aage kuch arguments usko dediye jaayin to wo khud hi usko uthaa ke chal pade. Abhi tak joh hain karte hain wo ye hai ki jee main ko chalaaya aur phir see out aur see in ke through ko promp the aur user se input li. To kai dafa yeh hota hain ke jee hain pata hota hain ki input kya deni hain yaa kis noiyat ki input hain. To agar hum command line pe hi desa kain to hain program ka naam 53 students flani cheese aur program chal jaaye. Yeh joh command line arguments hain, inko program ke andar ghusane ke liye hain hain ek mechanism chahaye. See mein yeh mechanism joh hain, yeh arg see aur arg vee. Yeh doh traditional naam hain. Yeh to variable names hain. We can use whatever we want. But the arg see stands for account of the number of arguments. So, argument see, count of arguments. And arg vee stands for a vector of the arguments. Ghabraani ki baat nahi sirf terminology hain. Vector ka matlab yeh hain hain ke ek cheese jis ke andar muhtlif cheese hain maujood hoon. So, yaha pe hum strings ki baat kar rahe hain, a vector of strings. Abhi joh pehle hum ne discussion ki, I think banaw it should be clear that a vector of strings is nothing but an array of strings. Array of strings kya hain? A pointer to a pointer. 2 dimensional array banjaya gana strings jah rahe hain. Kaise strings hain to unke number of characters bhi hain aur kaise strings bhi hain. So, rows bhi hain. Columns bhi hain. 2 dimensional array bange. 2 dimensional array ko hum ne kaat hain bhi. A pointer to a pointer. Or a pointer to an array. So, the way we normally write main ki command line. So, main hum likthe hain main phir parenthesis ke andar hain likthe hain int arg see because the count of the arguments is always an integer ke di baat main ek cheez baat hain do baat hain theme baat hain. So, int arg see comma char star star arg v, which says arg v is a pointer to a pointer to a character, which as we know is a 2 dimensional array of characters aur an array of strings. Jab ye main istra se declare hua ho, to program ke andar aap ye arg v wali cheezon ko actually access kar sakte hain like strings. So, you can pass command line arguments into the program. One interesting experiment for you to do would be to just write main int arg see character star star arg v and in the body of the program aur kuch na karein pehle kayain ke ji arg see ki value likho. So, see arg see out less than less than arg see aur pehle new line kar le, to aapko nazar aayega ye kitne arguments pass kie gae aur pehle next line pe aap kahin ke ji star star arg v ko bhi print kar ho, double b referencing kar le, ta ke aap ke aapko pehle string de de, yaar star arg v kar le, de ke nao pehle string output karega. Aur kuch nahi kyaa bhi aur iss program ko aap chana hain. What do you think? You think the answer should be zero. Koi argument nahi humne diya aur aage null string ke ji koi string nahi mili. Not true. What happens is ke arg see ke anda jo ginti hain wo saare argument vector ko count karke maujud hain aur argument vector ka pehle element jo hain wo program ka apna naam hain. Interesting. So, the program in C and C++ knows its own name. So, if you run this little two line program, you should be able to see that the count of the arguments is one, not zero. And the first argument is the name of the program itself. Aur pehle aap iss ko koi command line arguments bhi dein. Wo command line arguments ke liye aapko command prompt pe jana padega. Lekin dev C++ me bhi aap chalate waak niche command line arguments deshaktin hain. You can explore dev C++ or talk about it on the discussion board ke ji command line argument kese deni hain. Normally, hum command line arguments space deke, jini white space character chhod ke hum bhi chme enter karthe hain. So, if you were to write a program jis me aap kate hain ke ji program ka naam aur pehre aage kate hain one space tu, to usko teeen arguments milenge program ka apna naam pehle a number as a character aur pehdusha number as a character. Ye yad rakhin ye character hain, ye integer nahin hain. So, agar aapne is as an integer istamalkar nahin, to you will have to convert them. We will put some examples on the discussion board or as part of the contents in your learning management system so you can see the usage of this construct. But it is very, very useful. Let's move on now. Ye bhi aabe is pe chhod dea kyun ke isko aagsi aur aagvi, ke shayat baad bhi hum aur baat kareen. Lekin it is useful to know that you can pass command line arguments and the program knows its own name. Now we want to move on and use the same concept of a pointer to a pointer in a real world program. Uske liye hum ne joh example choose kia hain wo aapko handouts me mila hoga. Kaafi lamba chhoda example hain. Meh strongly recommend karte hoon ke isko aap go through kareen. Ek ek line ko pade aur samjhe. Style issues ki andar iske andar style issues bhi hain so aap dekhen ke style kya hain program likhne ka. Again, I will reinforce. Laazmi nahin hain ki ye hi aap style adopt kareen apne liye. Aap apna style evolve kareenge over a period of time likhne ye bhi achhe style me likhha hoa hain. Iske andar hum ne character pointer array array of pointers to character. Ye istamaal kiye hoa hain. Inko declaration ke bak declare bhi kya hoa hain. Phir aage inko manipulate bhi kya hoa hain. Aur phir kuch programming tricks bhi iske andar shamil hain is program ke andar. Jo problem is program hain humne tackle kya hain. Wo hain ki jise tash ke patna ki deck hoti hain. Onko pehle hain normally randomly shuffle karte hain, phantte hain aur phir bandte hain, deal karte hain. So, this program will actually randomly shuffle a deck of cards and then deal it out. So, it's a very interesting program. Ke ji sari output ye hai iski, wo hogi ek random dealing of a deck. And every time you run it, you should come up with a different set. Ke ji phir koi aur pata hain, phir koi aur pata hain. So, you can use it in a real world game. Agar aap game banana chahin computer game using cards. Let's look at a few things inside this program. Pehli cheez ye hai. Aab bhi aap thora sa analysis ki taraf jaar hain. Phir kuch algorithms ke upar baat karunga. Code aap ke paas hai. Kuch aap screen pe dekhenge. Pehli cheez ye hai. Ke ji humne problem ko dekhah. Ke ji ye deck of cards ke saar deal karta hain. Aur humne card ko identify karna hain. To card ko identify kese kiya jaata hain. Pehli uska ek face hota hain. Ye ne suit hota hain. Ke ji ye hum urdu me to hukum aur chidiya aur ishtara baat kartne hain. In gresi me usko spades, hearts, diamonds and clubs kehte hain. So, hum wo lafs istamal kareinge. Uske baad agar pattaon ko dekhin to unk peh upar values bhi hoti hain. Ye kese shuru hoke baad shaatak jaati hain. Again, in gresi me usko ace. Peh 2 ko hum dews kate hain. Peh 3, 4, 5, 6. Peh Jack, Queen, King. So, tera patte hota hain. Ek suit ke andar aur 4 suits hota hain. Ek deck ke andar hi nahi. Baavan patte hota hain total. Hum inko program ke andar represent karna chaar rahin. So, we want to use English. We don't want to use numbers. We don't want to say something like 2nd row and 3rd column. We want to say a 5 of clubs. So, iss ke liye pehle to angresi store ke jaai kisi array ke andar. So, hum ne ek array wo deklear ki hai suit ki. So, it is 4 star suit 4. It's an array of 4 pointers to character. So, when it is pointers to character, we know ki pointer can store a string. Aur ye iss tera se kyun kiya hain ta ke wo variable naam hain. I mean diamond lamba hain. Heart chhota hain. Clubs usse chhota hain. And so on. So, hum ne aage character strings jein hain wo initialize kardi hain declaration ke wak thi. So, ek array of pointers to character hain suit uske andar aise, sorry, spades, hearts, diamonds or clubs ye store kardi hain. Dusi jo hain wo patteon ki value wali array hain. So, let's say, again, 4 star values 13. Jo ke tera values hoti hain. Aur pheer aage humne unki angrazi likhi hain. 1, 2, 3 nahin dikka humne double quotes ke andar. Ace, deuce, 3, 4, 5 and so on, all the way up to king. Ye do arrays of pointers to character jab initialize huin. To memory me exactly utti jage reserve hui jitni hum chaate the. Koi jage waste nahin hui. So, this is an important point to understand ke if you declare and initialize like this, you are not wasting space. The other thing that we have done in here is ke aage dekhin ke const keyword lagaya hua hain. Ye const kyun lagaya hain. Koi logic hain iske piche. Obviously, we don't do things just for the heck of it. The logic is ke ji yeh cheezan toh define ho rahin hain. Ek defa ke ji clubs ne clubs hi rahin hain. Spades ne spades hi rahin hain. Us ne koi change nahin hona. So, hum chaate hain ke unko arrays me store karein. Lekin yeh nahin chaate ki yeh kisi tarike se enki values badal jayin. Yeh overwrite ho jayin. Yeh koi gabe jaa jayin. To hum ne const keyword de dia. Ke ji declare ho ghi, define ho ghi, istamaal karein. Lekin change aap nahin kar sakte. Same applies to the value of the cards. So, values jo array hain. Array of pointers. Us ke andar bhi values likhti aur usko const kar dia. Ab rahi ghi baat deck ki. So, deck jo hai ho ghi bhavan patto ki. Yeh kyunke chaaru suits, tera cards per suit. Deck is the one, jisko hum shuffle bhi kareinge aur deal bhi kareinge. Toh aap iskinde thodi algorhydmik cheeze hain. Deck ka pehle size kithna hona chahiye. Well, it can be either linear, 52 or it can be 4 suits, 13 values per suit. And logically, it makes sense to have a two-dimensional array with 4 suits and 13 values per suit. So, usko air buckets me 4, 13 se usko declare kiya hain. Patto ko hum randomly distribute kar na chaatne hain. So, hum deck ko pehle load kareinge phir usko shuffle karte hain aur phir usko deal karte hain. How do we do this? Well, card number ki hain ek loop define karke inko shuffle kareinge. Let us see how that happens. Deck ko hum ne initialize kar bhiya to 0. It means it holds no cards at the moment. Yeh aap main thode sa algorhydm ke baat kar hain ta ke sochne ka andaz hain. Hum kareinge yeh ke hum ne baavan patte distribute kar na hain jo bhi unka number ho. Hum randomly ek suit chuse kareinge aur randomly uski ek value chuse kareinge. Aur waha pe card number likh denge. Wan se churu ho ke 52 tak card number likh denge. Which means random suit yeh ne aapne clubs liya hain yeh hearts liya hain yeh spade liya hain wo randomly chuse kare liya. Aur randomly uski value esse leke king ta koi chuse kare li aur usko ek number assign kar diya ki jee 1 hain yeh 10 hain yeh 13 hain yeh 15 hain up to 52. Aap yeh samaj lein ke ek 2 dimensional array ke andar aapne kaafi randomly number likh diye hain. Aap agar iss array ko print karne ke liya hum kahin ke jee sab se pehle jahaan 1 likh hain uski row and column is tamal karte hua uska likh hain ke jee suit konsa hain aur value konsi hain to you will realize ke this is a very random shuffling of the deck. So let us see how we do this. Agar aap shuffle wale function ko dekhin to deck humne initialize kar diya to all zeros 2 dimensional array of dimensions 4 and 13 aur usko pass kar diya to the shuffle function. Array ko pass kiya hain it will be passed by reference to make sure that shuffle knows how to deal with the 2 dimensional array wo joh aakhri wale columns ka dimension hain wo aapko batani padti hain so wo 13 aapko batana padega diye hain and then we go in and see what we do hum kyaate hain ke jee ek se shuru ho jao so we use an integer variable and we run a little loop which we will run 52 times. So we start from 1 go into the loop and now we generate a random number for the suit. Soot ke liye kya karna cha hiya how do we generate the random number look in your notes it's in front of you but I would prefer that you think chaar suits hain thik hain spades hearts diamonds clubs inko hum ne array me daalna hain aur array ki indexing c ke andar 0, 1, 2, 3 hoge 4 dimensional array hain the number of rows is 4 so 0, 1, 2, 3 agar number generate karna hain hum ne using the random number function aapko random number function aapko pass modud hain to hum kyaingin a random module of 4 so random module of 4 hoge hain that will give us an answer which is 0, 1, 2, or 3 ishi tara kolum determine karne ke liye hum random module o 13 kar dete hain which generates a random number between 0 and 12 inclusive this gives us the row and column kya hum sida sida ye jo row and column hain hain usme deck me deck of this value of row and this value of column ke andar card ki value assign kar hain jo bahar wali loop chal rahe hain wo card ke upar chal rahe hain should we just do that? the answer is no we can't do that because ho sakta hain ke har dafa ekhi random number nikal rahe hain to aap uske upar card number 1 liktinge phir card number 2 liktinge phir card number 3 liktinge phir card number 2 liktinge phir card number 3 liktinge it won't work so what we want to do is ke pehle deck me ye dekhah jah hain ke kaunsi next available khali jage hain kaunsi next available khali jage hain in other words agar koi row and column random number ki bhaja se wo hi answer hain jo pehle hum ek dafa proses kar chuke hain to andar hum ne random numbers ke baad ek choti si loop chila hain first we say while ye jo deck ki value joh hain wo not zero hain dekhin deck ko hum ne zero ke saath initialize kiya tha so while it is not zero ye loop chalti hain aur jab zero mil jata hain which means it's an unused space aur unused position in the two dimensional array deck hum loop se bahar aajate hain us jaghe pe hum jaake card number assign kar deti hain rand ke upar aap ne dekhin ek line hum ne beginning mil ikhi hain s rand ke naam se ye bhi useful hain mai eski thori der mein baad karunga because talking about that now we'll get away from the logic of this program once we have gone through this iterative procedure for all 52 cards what is happening is hum ne random row aur column ke upar hum ne ek card number likh diya hain aur row represent kar rahi hain suit ko aur column represent kar rahe value ko ye shuffling is complete function is over you go back to the main calling program yahan se aage hum deal kar na chate hain dekh ko deal karne ke liye hum karenge kya kyunke hum ne woi random shuffling wala output dini hain hum kahinge ke ji pehle dhundo ke card number one kahaan pe hain ish dekh ke andar jo jahaan pe wo mile so hum ne kaata random row aur random column woi gaya hain jahaan pe wo card number one mile jahain to uski row ko istamaal karo kyunke row hume locate hogei hogei as a number aur row ko istamaal karte wo jo suit array declare keethi wahaan se suit ka naam likh to aur ishi tara column ko istamaal karo jiska answer koi number hoga aur jo values di uski array me se uski value likh to so now look at the deal function it's quite simple again it is for card equal to 1 to 52 which means 0 to 51 karlein 1 to 52 karlein doesn't matter us value ko leke hum ab dekh array ke andar usko dhunthein so it's a search koi ze ruat ne hai isk andar koi fancy search lagane ki koi binary search ya kuch haise lagare hum simple simple brute force search karte hain ke ji while deck of row column is not equal to card yani ye wali value nahi mili utni de tak loop chalao it's a double nested loop pehle row pe upar wali loop hai pehr andar wali loop column ke upar chal rahe hain jab aapko wo value mil jaati hain to wahi se aap bahar nikal sakte hain yaha pe again you could use break to get out of the loop but then you would have to use 2 breaks to get out of the loop double nested loop hai jab card mil gaya to aapko andar wali loop pe bhi break hain aur pehr bahar wali loop peh koi condition check karke break lagane so all we've done is as soon as we find the value we simply print the answer okay so we you see out ab row ke bhi value chal rahe hain ek loop me aur column ke bhi chal rahe hain jaha pe bhi aapko card ke value mili wahi pe row aur column ke value automatically aap ke paas hain you can use them to print the word from the suit array so if you say print suit of zero to wahi pe shayad wo spades likde aur agar aap kain print suit of one wo baha pe hearts likde and so on aur pehr saath value hain to values ke li aap ke paas column index miliya ho ga card you locate ho gaya hain so now you can start putting out a print out jo aap dekhle aap ke aapke example me diya hua hain so you will start getting a table which is also presented as one example of the random output aap chaahin to ye sara copy karke randomly har dafa ye dekh ko shuffle karke aap ko present karega lekin code copy karke compiler me daal ke chalana isn't the objective objective is iss program ko zara study karein kaafi kaafi interesting cheezin constructs algorithm wise wo iskender present ki jaa rahin hain aap ke paas nested loop ka example aara hain aap ke paas array of pointers ka example aara hain aap ke paas variable size in an array of pointers ka example aara hain aap ke paas random number ki usage in a real world problem uska example aara hain aap me iss rend ki bhi baat karta chaloon dekhin computers wo random numbers hain generate karlethein through this rend function kya is it truly random answer is it isn't truly random agar aap har dafa sequence mein numbers de dega lagin ke bade random ke jee pehle 1 aaya 15 aagia 19 aagia 0 aagia 2000 aagia depends on the range lagin ke bade random lekin har dafa aap generate karenge to har dafa wo hi sequence aara wo ga baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar baar So, time function on most of our systems returns a number of seconds or seconds are coming from the system clock. So, every time you try to run the program, time function will give you a different number of seconds. Different number of seconds is now a different number, which means the random number generator now generates a different sequence of random numbers. If you want to generate a truly random number, then how will you do it? Have you ever thought about how to generate random numbers? But the random events in the real world affect so many variables. If a true of me engineer or scientist is sitting there and says there is no such thing as a random number, then the exact answer can be written as a random number. True, if you had a computer big enough. Shadako introduction to computing may be bad key or may be earlier bad key. The big super computers, the powerful, tereen computers, the big supercomputers, what problem are they having to solve? Do you know? Yes, they do do. The simulation of nuclear bomb or the cockpit simulator, but the one problem that they work on most is weather prediction. It's a scientific problem, but if you think of the number of variables, there is something else effect. We are talking to the chaos theorists, they will say that in South America, a titli hit the ground in a jungle and after two months, the cyclone hit Thailand. And because of that, the cyclone hit here. You see, we are in a linked system. It becomes a little exaggerated example, but trying to solve it using computer equations, it is such a horrendous problem, it is such a huge problem that computers are working a lot on weather prediction and they don't have a solution. If you talk to their weather bureau in the west, they give you very accurate prediction for the next day or two days. After a week, reasonable. After a month, forget it. It's just an assumption that the sun will come out. Anyway, I was getting off the topic. But when you try to generate random numbers, you have to think about how to generate a random number. When I was a child, I used to open a book and say page number, then I closed it, then I opened it and said page number. Fairly random, but it's a limited set. We say purely random number. Back to our topic. We have used s-rand to start the random number generator at a random position and then we used it to generate row and values, rather suit and values for the cards and populated the deck array. The interesting thing that we are going to look at is how we have found empty places in the deck array and how the number of cards is written in it. Another interesting thing is that we have randomly written numbers in the deck array and how we have printed them. These are useful techniques because they will help you in any other problem. So I want you to view this program very critically and less from a language but more from an understanding perspective. Let's stop here today. We have seen multi-dimensional arrays, pointers to pointers, arrays of pointers. We talked about a small command line argument. We will talk about it later. And then we presented you a comprehensive example in which I will talk again. You need to understand it. Just treat it as an example as a code. Till next time. Good-bye.