C_80 Void Pointer in C | Detailed explanation with program

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so in the series of learning programming in c we are discussing pointers in c in pointers also there are some special pointers like void pointer generic pointer null pointer dangling pointer and these pointers are also very helpful right so we are going to discuss these pointers one by one in this video i will discuss word pointer everything about poet pointer like what is void pointer the need of word pointer why we use word pointer how to declare this pointer how to use this pointer right with the help of a program right and i'll show you that program also on my laptop practical also will see right everything will discuss about this pointer in this video and one by one by one in later videos you will discuss dangling pointer null pointer all this these special pointers will discuss right so you'll also see how this pointer is different from the other pointers we have discussed like integer pointer character pointer float pointer everything about this pointer will discuss in this video every single detail right with proper program but before that just want to tell you one thing if you are looking for a great career in software development then you must think about the points like what's trending trending in the industry and the questions being asked in the interviews how to improve your course your cranking so here an academy brings you a platform where you can get access to the weekly shows which you can watch live and the host of these shows are seven star coders on code chef and are industry experts with years of experience and they are working with some of the top companies like amazon google linkedin and they'll be covering a lot of content that would be really helpful for you like in live episodes you get an opportunity to ask take a charge about top 20 questions and industry leaders directly about their recruitment process in startups and mncs and what's the eligibility criteria and how to apply uh for them not only this you can also participate in mock interviews and learn courses on programming languages cloud computing blockchain and crypto tech aspects of digital marketing and data analytics and if you have ever wondered about the questions being asked in the top product companies interviews then there's a show where their host will walk through the top integral questions being asked in the interviews of the companies like facebook apple amazon and how to answer these questions and respond in a way that will help you to crack these interviews and here you'll also get a chance to come live with their host and get your you know queries resolved on the spot and all this and much more you will get at just a nominal view of rupees triple line for entire year and if you use my code jkl10 you will get it at a double line for entire year so you can find out the details of the show and the badge using the link that i'll put in the description box of this video so you can go and check out so now let's discuss what is word pointer i hope you know the meaning of this word in general term in english term like khali or empty right so it's like if there's a glass and that is empty that is void you can fill that glass with maybe water with the some other drink or with the milk anything you can you know put in that glass right so apply the same concept here also try to relate that thing void pointer means this pointer is of void type means this pointer is having no associated data type if you will see the definition it me that may be on internet or in any book then you must you must see that word pointer is what it is not having any associated data type that is in simple terms that is a the same example you can take an empty glass you can fill that glass with either you know with the water or with milk or with some other drink or anything right so same this pointer is having no associated data type with it so you can convert this pointer in any other pointer also now whatever i am saying what's the meaning of that thing see first of all if i write a pointer something like this in star p one is float star fp here i'm writing i p or here i'm writing c p it means there are three pointers this is integer pointer see data type of quantity is not integer it means i p is a pointer which is pointing to a into data type or maybe this is storing an address of a variable whose data type is integer or simply we call it as integer pointer or pointer to integer this is float pointer or you can say pointer to float this is pointer to character right so they they are having their associated data type the sources data type of this is the data type which is associated with this pointer is in with this float with this cap but void pointer is having no associated data type so how to declare this pointer see the syntax is same obviously if it is a pointer you have to use a string this will tell that it is a pointer name here you will write pointer name suppose i am writing pointer name word pointer that is uep so what you will write here at the place of this data type simply we will write what this word this keyword void so this is what a declaration of word pointer right i hope you understand what is word pointer it is it is not having any associated data type right so you can convert it into any other data type you can type cast it right here it means this can store address of a variable like if our address variable is in a another variable i am taking float b one variable i am taking care c so this pointer can store i p is equal to address of a only this is possible this can store address of a only if you write i p is equal to address of b this would be wrong and what you can write fp is equal to address of b and this pointer cp is equal to address of c right but here this pointer can store address of this int variable also float variable also care variable also right so its like a generic pointer same in empty glass we can fill maybe water some other drink or maybe milk anything we can type cast it so we can type cast this pointer for that you have to type cast this pointer directly if you write suppose here i am writing vp is equal to address of a it means now this word pointer is storing address of this variable a and supposing a i am having a is equal to 5 but if you will print like printf percentage d and whatever in a i want to print in a i have 5 and this we p this pointer this is pointer this is pointing to a suppose address is thousand so in vp we have address of a that is thousand so if you want to access this using this word pointer what you will write d reference will dereference this pointer i hope you know this because we have discussed these concepts i know in our previous videos of pointers right it means a strict vp value at this address here we have thousand so it should give five but it is wrong you cannot dereference a void pointer it will give you error first of all you have to type cast it because see when you dereference then it will see suppose i am differently referencing this ip i am writing here i p i p is equal to address of a suppose this is not v p this is i p this pointer right and s trick i p so it will give you phi this is correct because this is integer pointer this is no word pointer so now when you dereference it it means compiler now no address the data type of this pointer the associated data type with this pointer is integer means now compiler no in modern compiler obviously it depends on machine to machine but i take like in modern compiler integer take four bytes so now compiler no [Music] one two three four suppose in memory within these four bytes this a the value has been stored five converted into binary form like thirty two bits and then this five has been stored here and address of first byte is thousand and thousand and one thousand and two thousand and three something like this right so now value at this address address is thousand address is thousand so now from here we want to access now associated type is integer so when you apply dereferencing now the compiler know that he has to access four bytes one two three four because data type is integer that is why the data type is needed when you dereference that pointer right so now it will access four bytes and it will give you volume so same if you access dereference this character pointer character will take one byte so now compiler know by seeing this data type compiler will know that he has to access only one byte because their type is character right same float if float is there means four bytes so it has to access four bytes but here we are using suppose vp now what is what it is not a data type now how compiler will know that [Music] it has to access one byte or four byte or how many bytes compiler doesn't know so how to access this word pointer how to dereference this word pointer how to get the value right value may be within in one byte or value maybe in four bytes no no it is word pointer right that is why we we cannot dereference this word pointer i hope you got the reason why you cannot dereference this word point right if not then you can ask me in comment box maybe in another maybe in another video i can tell you the process in a separate video right so now that is why it will give error so first of all we will have to type cast this one typecast means now i am storing in vp address of a so here we have vp i am storing address of a and the type of this is what integer so we have to type cast it into integer pointer so now how to type cast it here rather than using this what you will write int asterisk vp so first this word pointer would be type casted or you can say converted into an integer pointer and now we apply this dereferencing operator right now it will give you what value 5 because now we have converted into int or we you can say type casted into integer pointer so now compiler no if in then it has to access four bytes so data would be in four bytes so starting byte is this so it will access thousand thousand one thousand two thousand three till thousand and three four bytes and obviously this is integer type and this would be stored in 4 bytes only so definitely you will get 5 right now if i write if i write something like this vp is equal to address of cp sorry address of c i am storing vp this address variable is what character type right so here in c suppose i am storing character as uh zero yeah zero is character it's not like that abcd is only character whatever you will write in single quote that will be in character a single character you can write so if you write zero here so zero would be considered as a character right so now address of c now vp is suppose here we have this is c here we have 0 obviously in that form like in 0s and one form that would be stored right and now we p this is a pointer and this is pointing to here suppose address is two thousand so it we are storing two thousand now now how to print how to print this is character we know this is character so we'll use percentage c asterisk first type cast type cast into a character pointer so we will write here care s print and now name is v that's it first of all it will be type casted into character pointer and then we'll de-reference it so d reference means value at this point the value is what zero so it will give zero i hope you got this and if you write here vp is equal to address of float variable so before printing type cast into float and that it will print floating value suppose in b i have one point one one so it will print one point one one right so simple point about word pointer there is nothing much about word pointer it is not having any associated data type you can convert it into any other pointer or you can type cast it into any other pointer right so now what's the use maybe you think that rather than type casting obviously ultimately we have to type cast it so rather than this directly use an end pointer and directly dereference that pointer what's the use of using this word pointer so here if in the same program same program if i'm using this int also float also care also so we have to declare three pointers one is for in one is for float one is for character but if you use this word pointer no need to declare these pointers you can access all these three values using single pointer word pointer only a single pointer how i know i i hope you know the answer first store the address of a typecasted and print then assign in this address of b while printing typecast it then assign address of c while printing typecast it and you can print you can access all the three values three values of different different data types so here we are using only one pointer we are using only one pointer and we are accessing values of three you can say data types integer also float also care also one more thing when we use mellow and k log we will also discuss these things these are built-in function for dynamic memory allocation so they return what word pointer right when they assign they return memory like they return word pointer to that memory so in that memory we can store any uh value like integer also float also character also right so there also these word pointers would be used right in malloc and kellogg so that also will discuss when we discuss dynamic memory allocation these are advanced uh you know concepts and see right so that is why we use i guess uh word pointer you you are clear with what is word pointer why we use word pointer like and you can say what's the need of word pointer now let me show you know practically we'll write down some code and we will see use of word pointer right so now let me create a file here i'm taking name.c right and i am taking only one pointer like void asterisk vp right and i am taking in a is equal to five and one more thing that is float suppose i am taking float b is equal to 1.56 and care care c at h is equal to uh anything you can take like i'm taking c right and now i'll access all the three variables using one pointer only so i'm first of all i'm writing vp is equal to address of a and now i want to d reference this a is equal to we are printing value of a and see if you dereference like this a string will be simple so it will give you error let me run this here we it is giving a dereferencing word pointer and invalid use of word expression so we cannot just de-reference this word point to something like this now we have to type cast it so i am type casting it into integer pointer first and see now let me run this and it will print a is equal to 5 see see it is printing the value a is equal to 5 right now i want to access that variable float so in vp i'm storing address of b now so now this word pointer is pointing what float variable so now b value is equal to percentage f and here i am dereferencing this now so we have to convert it into float you have to type cast it into float see let me run this and it will give you a is equal to uh sorry that this is equal to five b is equal to one point five six zero zero right and now same address of ch and let me print c equal to percentage c and as trick we now we have to type cast into care right and now let me print this sorry run this see it is printing abc ch value all the three values so we are accessing all the three data types variables with a single pointer only so that is benefit of using a word pointer that is why programmers use this word pointer right
Info
Channel: Jenny's lectures CS/IT NET&JRF
Views: 9,972
Rating: 4.9578948 out of 5
Keywords: data structure tutorials, operating system, data structure and algorithms, jayanti khatri lamba, jennys lectures, jenny data structures, jennys lectures DS, jenny lamba, jennys baby, jennys lectures baby, data structures, pointers in c, introduction to pointers in c, problems on pointers, pointer questions and answers, void pointer in c, gate cs lectures, ugc net computer science preparation material, file handling in c, functions in c
Id: Sq0xsFBJ_nM
Channel Id: undefined
Length: 19min 53sec (1193 seconds)
Published: Tue Aug 24 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.