filmov
tv
concept of void pointer

Показать описание
Today we learn and understand very interesting topic in programming void pointer. void pointer full name is very important pointer, because it has very magical property. if we create pointer of any datatype like character, integer, float, or user defined structure, they all have fixed, because we can access or assign their datatype variable address only. Fixed pointers increase or decrease according to their datatype size. If you create a array of any data type, then the increment or decrement will depend on particular datatype size. For example, character pointer increases or decrease by one, integer pointer increases or decrease by two, float pointer increases or decrease by four, in case of user defined structure the increment or decrement depends on the structure size. In our case defined structure person, which total size of one variable is equal to 13, because inside this structure has two variable, name and age. The name variable is character array, so the size is 11 and age variable is integer, so the size is 2, so the pointer of person structure increment or decrement by 13.
In this program created few variables and pointer to understand. All names are character variable gender & pointer variable c, integer variable hp & pointer variable i, float variable rating and pointer variable f, structure person variable pinfo, pi and pointer variable p. Also finally created one common void pointer variable vip for our program. Now next all pointers assign with address by using their variable name with address symbol. Next by using asterisk symbol in front of pointer variable name, to access value of pointer. Next the same steps repeat again one by one assign and read value by using void pointer. For example, to assign, in our case assigned character pointer to void pointer, so first write void pointer name, then equal sign, then datatype name in round bracket with asterisk symbol and finally pointer variable name of particular datatype. Now next to read value from void pointer, need to convert particular datatype. For example, in our case first write asterisk symbol, then add round bracket, inside round bracket again adds round bracket with datatype name and asterisk symbol, then finally write void pointer variable name. We cannot create void datatype variable, but we can create void datatype pointer. Because the size of void is zero, but the size of void pointer is equal to size of integer datatype. Reason, pointer is used to store the address of variable of particular datatype, and variable is created on ram location, so the ram location mapped is in number. To check output, compile and run. Hope example video is helpful for you to understand the concept of void pointer. Thanks for watching.
In this program created few variables and pointer to understand. All names are character variable gender & pointer variable c, integer variable hp & pointer variable i, float variable rating and pointer variable f, structure person variable pinfo, pi and pointer variable p. Also finally created one common void pointer variable vip for our program. Now next all pointers assign with address by using their variable name with address symbol. Next by using asterisk symbol in front of pointer variable name, to access value of pointer. Next the same steps repeat again one by one assign and read value by using void pointer. For example, to assign, in our case assigned character pointer to void pointer, so first write void pointer name, then equal sign, then datatype name in round bracket with asterisk symbol and finally pointer variable name of particular datatype. Now next to read value from void pointer, need to convert particular datatype. For example, in our case first write asterisk symbol, then add round bracket, inside round bracket again adds round bracket with datatype name and asterisk symbol, then finally write void pointer variable name. We cannot create void datatype variable, but we can create void datatype pointer. Because the size of void is zero, but the size of void pointer is equal to size of integer datatype. Reason, pointer is used to store the address of variable of particular datatype, and variable is created on ram location, so the ram location mapped is in number. To check output, compile and run. Hope example video is helpful for you to understand the concept of void pointer. Thanks for watching.