 Hello friends, I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I am going to explain how you can use void pointer in C language. Before start, if you go to description of this video, you will find links of various playlists related to C language. So you can follow them too. So before starting pointer, sorry void pointer, let me write these statements. So first is in S, S, P, A, then float, S, Q, B, then cad, S, S, R and C. So here you can see I have integer pointer, it's variable, float pointer, it's variable, character pointer and it's variable. So if I want to store address of integer variable, then I require integer pointer. If I want to store address of float variable, then I require float pointer. If I want to store address of character variable, then I require character pointer. So for different variables or different type of variables, I need different type of pointer. Now if you want to reduce number of pointers, let's say you want only one pointer that can store address of int as well as address of flow variable address as well as address of character variable Then in place of declaring all these variables separately, you can declare one pointer that is known as point pointer And further you can typecast that pointer so that you can find out specific value related to a particular point So now we can avoid these statements and we can declare one common pointer as point pointer And let's say I have variable A, integer type, variable B flow type So A is having 5 and B is having 2.5 So now continuation with this if I write P equals to address of A So this is a valid statement P is a void pointer and this void pointer can store address of this A variable that is of integer type But whenever you are going to use that value, then you need to typecast that pointer so that you can have a particular value Because what will happen, let's say this is A, this is B, A is 5, B is 2.5, its beginning address is 101, its beginning address is 201 And let's say this is P which is having beginning address as 101 So now when I will be dereferencing this pointer, let's say if I write printf %d and asterisk p So p is having 101 and if I write asterisk in front of this So asterisk means value at address, address is 101 So 101 is the beginning address and value is available on R2 address, that is the competition up to address 101 and 102 Because A is of type integer, right? Now P don't know its type because it is void type, so it don't know its specific data type So it is unable to identify how many bytes or how many address it has to derefer Because right now it is having address of A If it is having address of B then beginning address will be 201 So P will be having 201 and if we write asterisk 201 So this time we need to dereference 4 bytes because B is of type float So for this reason type of pointer becomes important So to reduce number of pointer we used void pointer But now for calculation purpose again we need to typecast that void pointer into a specific type So before writing this, I need to write this in pointer and then P So I am typecasting P with integer pointer and now I need to write this asterisk So first P will be converted into integer pointer and then it will be dereferenced with this asterisk So it will identify value at address, so now P knows its data type and I belongs to integer pointer So how many bytes it will process to bytes So output of this will be 5 Now if I write P equals to address of B So this time P will be having address as 201 And if I write printf%f and asterisk P So again same problem arises because it means asterisk 201 So this time also P don't know what is my type because it is of void type So it will dereference, so how it will know how many bytes it has to dereference Or how many address pointer needs to collect to work upon So before processing this we need to convert it into float pointer And then we can dereference it so that it will print 2 pointer So friends I hope you understood If you want to reduce number of pointer then you can declare void pointer And whenever you want to process that void pointer then every time you need to typecast that void pointer into a specific type of pointer like I did And then only you will be having a proper value Otherwise that outcome will be a garbage value and your process will show you incorrectly So use void pointer but don't forget to typecast it so that you will be having the correct output So I hope you understood how we can replace integer pointer, float pointer and character pointer with void pointer And then further we need to typecast it so that we can use that problem So I hope you understood whatever I explained in this video If you want to watch more videos open my channel and have lots of videos Or go to description of this video and find links of various playlists attached So thank you for watching this video