 Hello friends, I am Sanjay Gupta. Welcome back on Sanjay Gupta Tech School. अब देख है, C-language video series अद इस वीडियो में जो तोपेख हैं दिसकरस करनेवाल हैं. उस तोपेख का ना मैं, Poynter. तो, जिनो ने C परना बिल्कुल बिगनें में स्थाट की है, as a beginner हो. तो उनो आपने senior से सुना होगा की Poynter वोग तोपेख होता है, C-programming का. तो असा बिल्कुल भी नहीं है, Poynter दी उतना ही, easy topic है, जितना की बागे topics आप आप आप आप बड़ चुक हैं. तो आप आप पुरी video series को फोलो कर रहे हूँने. तो में लास्ट जो video, इस video series लिए मराए था वो की, वो ता area of structure based, और उस से पहले मैं इस शुक्चा इस प्लिंग की आता. तो हम इस video series में अभी तक if else, loop, array, string, 2D array, 3D array, structure, union, इन सब को दिसकस कर चुक हैं. तो आप हमें जो next topic दिसकस करना है, Poynter. तो Poynter में जो points हम दिसकस करें यह वो आपके सम्ने में वेंच्यांट है. जैसी यह भीडियो बेखरे होता हैं और कमप्लित जाता है, और आप कोई भी दाउड मुस से दिसकस करना चाता हैं में भी दीटेल से हैं. तो आप मुस से कमिलिकेट कर सकता हैं. तो start करता हैं Poynter. And one more thing. अगर आप पूरी भीडियो सीरिस को पूलोग करना चाता हैं और आप के पास लिंक अवेलिपल नहीं हैं. तो आप मेरे जैनल पे प्लेलिस्ट में जाके सरच कर सकता हैं. तो start करता हैं Poynter. तो सब से बहले देखता हैं. बैसिगली Poynter कोता हैं. तो एक दो थीरेटिकल स्लाइट्स के बादा में सको प्रक्टिकली देखते हैं. तो Poynter is a variable which can store address of another variable. तो Poynter भी एक वेरिएपल होता हैं. तो ये थो थीरेटिकल स्लाइट्स के भादा में सको प्रक्टिकली देखते हैं. तो Poynter is a variable, which can store address of another variable. तो Poynter भी एक वेरिएपल होता हैं, बत Poynter, which stores value, रहीं किसी थुسरे वेरिएपल का अग्झैज़्ा से होती हैं. तो अख़ी आप लोग को ज़े अग़ भीरार्याबल ग़ी वी नाप्वब दश्टे करी था पहकलूँउ़ना करई से मएब वीरेबल को मैमरी लोकेट है तो ऍेपया नहीं से पहनागा और और फ्वोंगट्च्त़ए पाच्टी झेome. अगर कोई लेंवाग यह से आपके गर के पहार कोई पडाशा बोड लगावाए, जिस पर आरो बनाववाए और उस पे आपके कोलोनी के बिगनेग और आन्टिंग गर के नमबर से वो मेंच्याड़, तो वो आरो बेसिकली जागरेगा, पोईंटर का खाम करेगा, तो जो बन तो हम पोईंटर के ठू भी उस वेर्येबल तक पूँज से, तो अब एक चोटसा पिक्टोर्यल डाएग्राम देख लेता है आपन पहले, तो लेट सपोस यह अपना एक वेर्येबल आई, यह उसका एक मैंडी बलोग बनाववाए, अगर 16-32-bit compiler है, तो 4-byte मिलेगे, तो यह जाएंगे 101,102,103,105. तो मैंने बिगनिंग अडरस मेंचन कर देख से, आगे वाले अडरस अप यह भी लिए प्यलिट कर सकते है। आप एक और चीज जान लेखेगा, यह मैंने सर्फ एजुम की आई, अबी मैं आप को अडरस प्रिंट कर के ही बतावगा, तो वहापे कोई और वालिए प्रिंट होगी, विकि हमें नी पतागी कोंसा मैमरी लोकेशन हमें मिलेगा, तो हम सर्फ अजुम कर सकते हैं, अगर अगर आप एक द्रोंगी प्लीएट करना है। तो ये जो बलोग है ये ए वारीए पल के लिए। अगर और गडर से तब बदीर कोई आप के लिए, ये बग ये वारीएत बलोग है के लिए, अगर में समस्भे आद लिए लिए लिए, अगर और फ़ह्ती listeners को लिए ये एज रवफ लेगता है कर लिए, तो उस केस में आरे आप खुट से नहीं बनापाझेंगे आप सर्ख क्या करोगे एक पौईंटर बनावोगे और रन ताईमपर बतलत जब आपका प्रोग्यान एक्जिक्यूथ होगाए उसी ताईम पर मैमरी आलोकेट होगी तो उस ताईम पर आप वेरियबल का नाम नहीं दे सकते हैं अमें सिर्फ वेरियबल का एडरस ही मिलता है और उस ताईम पर एडरस को स्वोग करने के लिए सिर्फ वोगत स्वोगन काम आप आप पौईंटर तो पुंटर के बहुत लिमटेड यूज है, बत उन लिमटेड यूज को समचने के लिए आप को पुंटर का बेसिक पता हो नाची आप ता कि आप दिनेमिक मैमरी अलोकेशन जैसी जीस समच्वाओ. तो मैं इक बर इस को समच्वरिस कर देता हो, हम ने एक विरिएबल बनाया ए, उसकी वेलिएव फीफ विरिएबल का बेसिक आटर से 101, P-Pointer बनाया जिसका बेसिक आटर से 201, और हम ने M% A गे तु ए विरिएबल का जो अटरस ता वो किस को देखा P-Pointer. तो आई वो की ये स्लाइड आप को समज में आगे होगी, विरिएबल अलग बनाया, P-Pointer अलग बनाया, और विरिएबल का जो अटरस है वो मैं P-Pointer को असाँईट कर देता है. तो आब अभ अगर अपन आगे बड़े हैं, तो यहा थक समजने के बाद अप अभ कर में ने स्लाइट को दिखो, तो मैंने P-Pointer के बागे में थोड़ा बेसेख बताया आप हम P-Pointer आप अप अप अप आप कर रहा हैं, तो उसके लिए हमें ये जो प्रोगें हैं ये इंप्लिमेंट करना होगा बेखो इस में एक वेरिएबल बना दिया एजिसकी वेलिएव है फाइइप पी पोईंटर बना दिया थीगे पोईंटर में हम ने एक अडर स्टोर किया अब हमें ये प्रिंट्ट्ट एगे कैसे काम कर रहा है, भो देखना तो प्रिंटटट में एगे ये एक वलिएव प्रिंट करेगा पाइइइप किजा एक एगे वलिएव पाइइप है रहा, तो ये बी समस भे हाँँगा होगा look at star P implement it is 5 for sign, then P equals to address of A let me write a comment M% is address of बिरहा बाहगा परन्तर्त अफ पूर्षेंटी कुमाप पूर्षन्टी, अप कुमा अश्ट्रिष््क भी निकेआ इसको सेप या, और अप ध़म लण करेगे अप दिखोगे डोबर क्या प्रिन्त वहा के आपुमा प्रिन्त भी आपूर्षास्धूए. इआ इपको इवि खम्ँद़ ब्शाग़ आप आप हैं? ईया इपको इविख आप खम्ँद़् हा after even that then the ugmohing still unclear आ भी प्रेंट किया होगर है? बु�orge solution ईपको आपको आपको क्ऑो Harbor 101 अद्रेस पर लेलु क्या है, 5 तो it means, किसी भी पोईंटर में जब आप कोई अद्रेस असाइन करते है, पोईंटर में जब अप किसी वेरिबल का अद्रेस असाइन करते है, तो आप उस पोईंटर के तुए उस वेरिबल की वेलु को अच्सिस करेंगे, उपर तांगता असे, फिर लेक और प्रिंट अप लिखा, फिर मैं लिखा वैलु of P. तो वैलु of P प्रिंट करानाई मखला बेक अद्रेस, तो अप दिहान नक्येगा अद्रेस प्रिंट करानाई, यह तो आप को क्या लिखनाईगा प्रींट पि? इसे भी वेलिभल के अद्रेस प्रिंट करनाई प्रींट प्रींट लिखा. if you want to print the value of that address then use asterisk value of a through p what will you write? asterisk p now you will understand if you write only p then you will get an address if you write asterisk p then you will get the value of the address of p you will remember this now save it and execute it now the address will not print 101 the value of a is 5 the value of p is 2 2 f e 4 4 this is hexadecimal value and the address of a is 2 2 f e 4 4 both are the same one address is directly printed and the other one is p because we have already stored one address in p p already has one address and one address is directly printed so both are the same then value of a through p so we have used asterisk p so what is asterisk p doing? call it to the value of a so basically the star we are using means value at address so if you have an address and you have put a star in front of it then call it to the value of that address so I hope now you understand the basic of pointer we use %p to print address and %d to print value and even if you are doubtful then I have shared my details with you you can talk to me because this is a different topic it can be that you have doubts in your mind so you can discuss it now let's move ahead now here is the calculation so these two statements are the same we have added a new statement here and printf is the same now let's see what happens let's go to our code now let's add one more line a equals to a plus asterisk p and we have to print two things so I am going to comment them they will not execute us we will only print a and p so what is the current value of a? 5 and asterisk p I have already told you p has one address and what asterisk will do? it will give value to that address so p has an address of a so what is the address of a? 5 plus 5 and what will be the new value of a? 10 so a will print 10 now let's see what asterisk p will print so let's run it first so that you will understand what is coming in the output a is 10 and p is 10 you must be thinking that a is 10 but how did p become 10? p was 5 asterisk p was printing 5 so let's go back to the diagram see this is the current situation a is 5 the address of a is p so the statement we have written a equals to a plus asterisk p so a has given 5 plus if we write asterisk p so this was star and 101 so what is the current value of star 101? what is the current value of 101? 5 so 5 plus what is written here? 5 because what is the current value of 101? 5 so 5 plus 5 is 10 and in which sign is 10? a so what is the new value of a? 5 is 10 so when a has 10 so what is the value of 101? 10 now when we have printed a so a has printed 10 when we want to print asterisk p so what will it make? asterisk p means asterisk and the address of p what is the address of p? 101 so we have to solve asterisk 101 so value at 101 so see what is the current value of 101? 101's current value is 10 5 is lost 5 is erased and its current value is 10 so it means asterisk p will print the updated value so what is the conclusion? if a is modifying its value if a is modifying its value so the address of a will use modified value only can it be that a has 10 but 101 still has 5 because both have to point the same memory location so it means if in the variable you make any changes through its name so the address will use modified value only so when we have written asterisk p so p has patched the value of 101 so what is the current value of 101? 10 so the output in both the cases is 10 so now let's see one more example here also two statements are the same but now we have written asterisk p equals to asterisk p plus a so let's solve this now let's see in this the memory location we will not modify it through the name of the variable we will modify it through its address so again you have to keep in mind if any location is modified through its address so the name of the variable will also use modified value only so now we have to solve this so let's run it first so again you will see that the output is 1010 so now let's solve it so asterisk p means asterisk 101 so we don't need to write that so asterisk v means asterisk 101 so what is the value of 101? 5 so 5 plus a how much is it? 5 5 plus 5 10 so what is asterisk p? asterisk p means asterisk 101 means 10 is stored in the value of 101 so what is the value of 101? 5 5 will be gone and what will happen now? 10 so when you will print anything from asterisk p so it will print 10 now let's see what will a print so you see the value of 101 is 10 so what is the current value of a? 10 because 5 has been erased so now we have modified this memory location through pointer so the name of the variable will use the modified value so the output in both the cases will be 1010 so I hope you have understood this I have tried to understand theoretically and practically through the diagram but if you still have doubts then you can discuss with me so we have covered these two points now I will tell you by implementing a program sum of two numbers using pointer so till now you must have understood that we can store the address of any variable in the pointer and through the pointer we can access the value of the variable and modify it now let's give a small example so that your doubts are clear let's remove these now you must have understood this you can also implement this you can also implement this you made a pointer in a you have a safe address and I added 1 in asterisk p so now if we print a and asterisk p then what will be the output if you have removed the output 6 and 6 then you have understood otherwise you will have doubts so why 6? because asterisk p has pointed only one location a has 5 5 plus 1 is 6 so this will assign 6 on the address of a so when the value of the address of a is 6 then what will a print 6 will print so when you execute it then what will be the output so it means when you assign the address of the variable in the pointer then you can control the location of the variable so now let's make a program for example we have two variables using pointer so this is a5 b10 now you can also use pointer asterisk p1 asterisk p2 and asterisk p3 then write p1 equals to address of a p2 equals to address of b p3 equals to address of so p1 has one address p2 has address of b p3 has address of c it means p1, p2, p3 through a, b, c the memory location is respectively you can also access the values and modify them so now what you will write here asterisk p3 equals to asterisk p1 asterisk p2 so when we write on the right side of equals to then the value is fetched asterisk p1 equals to value at address which is stored in p1 so in p1 whose address is a so whose value is a so what you will get is 5 then asterisk p2 asterisk means value at address whose address is stored in p2 in p2 whose address is b and its value is 10 so asterisk p1 equals to a value is fetched asterisk p2 equals to b so what you will write here asterisk p3 asterisk p3 has address of c so whose value will be reached in c now see I will not print p1, p2, p3 I will print c sum equals to percent c now see input a, b, c through them then we have signed the address calculation we are doing through pointer but what I am doing in print is c I did not assign anything directly in c through whom I am assigning asterisk p3 so when I run it and show your output in front of you it will be 15 print sum equals to 15 so we did not directly manage the variable through its address we managed it through the help of pointer so I hope now you have understood the basics now let us move on now let us do the swapping of two numbers using pointer so let us perform the swapping so in the swapping the addition statement will be removed p1, p2, p3 has a, b, c there are three variables they have an address so now let us do the swapping then we use for swapping without third pointer see the swapping of two variables without using third variable but using pointer so see the value of a and b will be swept through pointer not directly so we have assigned 510 in a and b we have made two pointers the address of a and b now see the normal logic is a equals to a plus b so now how will you change it asterisk p1 because the value of a through p1 pointer you have to write asterisk p1 then again asterisk p1 plus asterisk p2 what will you write for b's value asterisk p2 now the next statement a equals to first statement a equals to a plus b second statement b equals to a minus b and then a equals to a minus b so 5 plus 10 here 15 15 minus 10 here 5 and 15 minus 10 here 5 so now we have to solve the second statement so what will be the second statement asterisk p2 equals to asterisk p1 minus asterisk p2 and third statement asterisk p1 equals to asterisk asterisk p1 minus asterisk p2 and this is the upper line remove it now print here a equals to d comma b equals d a comma b so see the logic of swapping we have used p1 p2 pointers in the logic of swapping we have not used a b anywhere but we are printing a and b so you will see through pointers we have accessed and modified a and b so it is written on the left hand side so it is modified so value is patched now we will execute it so you will see a is printing 10 and b is 5 and you can see here initially a was 5 and b was 10 so we have modified the values of pointers so till here you have understood now we will talk about pointer to pointer so that is also very simple this is a diagram a, p and q so a will be variable, p will be pointer and q will be pointer to pointer so basically pointer to pointer pointer to pointer if you want to store pointer then you have to make pointer to pointer so we will make a pointer to pointer to pointer so we have made a variable pointer p pointer to pointer to pointer q so when you make pointer to pointer you will have to use 2 stars so here p is pointer and q is pointer to pointer so p equals to address of a so p is pointer so it will hold a variable and q will hold p pointer so in the diagram you can see a is address 101 value 5 p is value 101 address 201 and p address 201 is value of q and q address 301 so in this way you can go to any depth of hierarchy if you want to store pointer to pointer then you can declare pointer to pointer to pointer and r equals to address of q but it is not required till these 2 labels you will have to use now if we print values a %d, %d %d so if we write a then 5 will come a is address p and a is address q so this is basically what we write as address this is value address and this is basically called as d reference so here we are assigning d reference and when a is address q sorry a is address p or double a is address q then this will be called as d reference so a is address p then you may be able to understand value at address address which is stored in p so that is address value so if we look at this diagram so in the diagram see what is address in p and what is value in p so now we have to solve this address q so if we take q value q value is 201 so here we have written 201 now solve this what is written inside the bracket what is written inside the bracket first solve this address 201 means value at 201 so value at 201 what happened 101 so if we solve this it will give you 101 means asterisk 201 and now one star is left so asterisk 101 means value at 101 so value at 101 how much is it? 5 so it means when you write asterisk asterisk q then what will it give you? 5 so this means when I run it then what should be printed 3 times 5 you can see this 5,5,5 a printed 5 asterisk p printed 5 asterisk asterisk q printed 5 so in this way you can assign a variable address in pointer and then you can manage any location now let's talk about area of pointer so if you have many pointers and you want to store only one pointer then you can make it area of pointer now let's take it now we have variables a5,b6,e7 this is the variable and I will make it area of pointer so you have already studied area of pointer so we have made integer area we have made character area now I am making area of pointer because we have used asterisk so this is area of pointer now if you want to store value then what you will write p0 equals to address of a p1 equals to address of b and p2 equals to address of c now if you have all address near p0 then you can process their values through p pointer now let's run a loop i equals to 0 i less than 3 i plus plus now let's sum it up s equals to s plus asterisk p of i see who will have address of a so you have de-referenced it and you have added it to s so here i and s have been de-referenced after the loop is over we have printed the value of s sum equals to %d s okay so 5, 6, 7 if we add 5, 6, 7 then 6 plus 5, 11 plus 7, 18 so you have seen that this addition operation you have solved only one area of pointer you don't need to write variables again and again this is a method that you can use see 18 is the answer so you should know that we can make the area of pointers now let's talk about next topic after that i will tell you some important points so what is the void pointer let's see so for this we have made a variable second variable float till now i have made integer, pointer but if you have float then you have to make pointer, float type so that we can store the address so what happens is the type of variable integer, float, different variables you have to make the pointer so what is void pointer void pointer says don't make different pointers for type you just make one pointer and the type of value sorry the variable address you want to store it but while processing the value you can typecast it so that you get the proper output so now let's do that so now we don't make different pointers here let's make one pointer void pointer p now look in p i have stored address of a in e i have stored address of a and whenever we store any variable then it is base address it doesn't know how many addresses are available so that thing is known as pointer type so if integer is pointer then it will process 2 or 4 byte as per compiler version like 16 bit or 32 bit if it is float pointer then it will process 1 byte so it depends on pointer type but what is pointer type void is not specific type it is generic type so when we print the value of a through e pointer then we have to use typecasting so what is that I have written %d so here I am writing a equals to %d now we have to print p now what we will write asterisk p but we have to tell what is the data type of p because p is the same type p doesn't know what type of pointer so what you have to write in bracket is integer pointer one more bracket then you have to write this statement so p is a pointer which we have cast in integer pointer and then we have to patch the value through r so this is asterisk it is telling that p is a pointer type okay now if we go ahead we have written p equals to address of b so what is the address of p now what is the address of p it is b variable and what is b variable so now we have to tell p again that you are a float pointer so what you have to do is you have to print the value of float so you have to copy it and here you have to write b equals to %f and now what you have to write data type is float so you can see this way that you have to declare p pointer as void and the void pointer will hold the address of a variable and the p pointer will hold so what you have to do is you have to tell that what type of pointer means what type of value you have to process it now you will see the values we have assigned through pointer we have to print a and b but we have not used a and b we have assigned the addresses of a and b to the pointer and printed it friends in this way I have explained all the points so there are some things that you should know about the basic pointer now we will talk points to remember so pointer always hold address of a variable so first point is clear pointer only stores base address of a memory location 8 variables 2 bytes 4 bytes, 1 byte depending on its data type but pointer always stores the base address beginning address then we can declare any type of pointer sorry we can declare pointer of any data type which I have already said that we can declare any type of pointer so integer variable so integer pointer float variable so float pointer and if you want to make a common pointer then you can do that but in that case you have to typecast that the variable address is integer variable float variable and last point is pointer dereferences an address according to its data type so the second point is that pointer got base address so how did the pointer know how much bytes it has to get and how it knows its own data type so that is why we have used void pointer so when we told that it is integer pointer P is integer pointer so P had beginning address so how much bytes it got how did it know that when it made integer type that it got 2 bytes on 16 bit so it got 2 bytes on 32 bit so it got 4 bytes on 4 bytes so it got 4 bytes on 32 bit and float always gets 4 bytes so it got 4 addresses so that is why pointer type is very important so when someone asks you if we can make a different type of pointer then you will answer yes you will ask why so you will say that pointer always gets beginning or base address so how many bytes dereferences it got how it will know so that pointer identifies so in this pointer dereferences and address according to its data type this is the reason we have to declare different type of pointer so in this way after doing this I have cleared all the points now on pointer you will get one more video which is lecture number 23 in which we will relate pointer with area string or structure so watch that video and you will get the playlist link of the entire video series in the description of this video so I hope that you are enjoying the video series so watch the complete series so that if you are a beginner you understand C programming and your interest in programming so thank you for watching this video