void single pointers ===================== In this section, you are going to learn about .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What is the use of void pointers ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow How to use void pointers ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Topics in this section, * :ref:`Syntax of void single pointer ` * :ref:`Single void pointer can not be dereferenced ! ` * :ref:`How to Typecast ? ` * :ref:`void pointer pointing to char ` * :ref:`void pointer pointing to int ` * :ref:`void pointer pointing to structure ` * :ref:`void pointer pointing to char array ` * :ref:`void pointer pointing to int array ` * :ref:`void pointer pointing to structure array ` * :ref:`Call by Value : void pointer ` * :ref:`Call by Reference : void pointer ` * :ref:`void pointer in expressions ` * :ref:`malloc with void pointer ` * :ref:`Array of void pointers : Basic Example ` * :ref:`Array of void pointers : Call by Value ` * :ref:`Array of void pointers : Call by Reference ` * :ref:`void pointer and nested structures ` .. _void_ptr_sp_ex_1: .. tab-set:: .. tab-item:: Syntax of ``void`` single pointer .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow void \*ptr; .. _void_ptr_sp_ex_2: .. tab-set:: .. tab-item:: Single ``void`` pointer can not be dereferenced ! .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow * Single ``void`` pointer CAN NOT be dereferenced .. code-block:: c :linenos: :emphasize-lines: 11 #include int main(void) { int a = 5; void *ptr; ptr = (void *) &a; printf("a = %d\n", *ptr); return 0; } In above code, Line 11 is NOT VALID .. code-block:: c $ cc p1_void_sp.c p1_void_sp.c: In function ;main: p1_void_sp.c:11:21: warning: dereferencing "void *" pointer 11 | printf("a = %d\n", *ptr); | ^~~~ p1_void_sp.c:11:21: error: invalid use of void expression * ``void`` pointer MUST be typecasted to type of originial data before using .. code-block:: c :linenos: :emphasize-lines: 11 #include int main(void) { int a = 5; void *ptr; ptr = (void *) &a; printf("a = %d\n", * (int *) ptr); return 0; } * Note Line 11 in above code snippet. This is the right method to typecase and derefer .. _void_ptr_sp_ex_3: .. tab-set:: .. tab-item:: How to Typecast ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow This is easy ! Just know the type of pointer assigned to void pointer ! * Look at below examples .. _void_ptr_sp_ex_4: .. tab-set:: .. tab-item:: void pointer pointing to char .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow void pointer can hold the address of a character * Step 1 : Define a char .. code-block:: c char a = 5; * Step 2 : Define a void pointer .. code-block:: c void *ptr; * Step 3 : Assign address of char to void pointer .. code-block:: c ptr = (void *) &a; .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Note that, ``typeof(ptr)`` is ``void *`` ``typeof(&a)`` is ``char *`` * Step 4 : Derefer void pointer to access char .. code-block:: c printf("a = %d\n", * (char *) ptr); * See full program below .. code-block:: c :linenos: :emphasize-lines: 11 #include int main(void) { char a = 5; void *ptr; ptr = (void *) &a; printf("a = %d\n", * (char *) ptr); return 0; } * Alternatively, you can use an extra pointer of type ``char *``. See below .. code-block:: c :linenos: :emphasize-lines: 11, 13, 15 #include int main(void) { char a = 5; void *ptr; ptr = (void *) &a; char *iptr; iptr = (char *) ptr; printf("a = %d\n", *iptr); return 0; } .. _void_ptr_sp_ex_5: .. tab-set:: .. tab-item:: void pointer pointing to int .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow void pointer can hold the address of an integer * Step 1 : Define an integer .. code-block:: c int a = 5; * Step 2 : Define a void pointer .. code-block:: c void *ptr; * Step 3 : Assign address of int to void pointer .. code-block:: c ptr = (void *) &a; .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Note that, ``typeof(ptr)`` is ``void *`` ``typeof(&a)`` is ``int *`` * Step 4 : Derefer void pointer to access int .. code-block:: c printf("a = %d\n", * (int *) ptr); * See full program below .. code-block:: c :linenos: :emphasize-lines: 11 #include int main(void) { int a = 5; void *ptr; ptr = (void *) &a; printf("a = %d\n", * (int *) ptr); return 0; } * Alternatively, you can use an extra pointer of type ``int *``. See below .. code-block:: c :linenos: :emphasize-lines: 11, 13, 15 #include int main(void) { int a = 5; void *ptr; ptr = (void *) &a; int *iptr; iptr = (int *) ptr; printf("a = %d\n", *iptr); return 0; } .. _void_ptr_sp_ex_6: .. tab-set:: .. tab-item:: void pointer pointing to structure .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow void pointer can hold the address of a structure * Step 1 : Define a Structure .. code-block:: c struct ABC { int x; int y; }; struct ABC a = { .x = 10, .y = 20 }; * Step 2 : Define a void pointer .. code-block:: c void *ptr; * Step 3 : Assign address of int to void pointer .. code-block:: c ptr = (void *) &a; .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Note that, ``typeof(ptr)`` is ``void *`` ``typeof(&a)`` is ``struct ABC *`` * Step 4 : Derefer void pointer to access members .. code-block:: c printf("a.x = %d\n", ((struct ABC *) ptr)->x ); printf("a.y = %d\n", ((struct ABC *) ptr)->y ); * See full program below .. code-block:: c :linenos: :emphasize-lines: 16, 17 #include struct ABC { int x; int y; }; int main(void) { struct ABC a = { .x = 10, .y = 20 }; void *ptr; ptr = (void *) &a; printf("a.x = %d\n", ((struct ABC *) ptr)->x ); printf("a.y = %d\n", ((struct ABC *) ptr)->y ); return 0; } * Alternatively, you can use an extra pointer of type ``struct ABC *``. See below .. code-block:: c :linenos: :emphasize-lines: 16, 18, 20, 21 #include struct ABC { int x; int y; }; int main(void) { struct ABC a = { .x = 10, .y = 20 }; void *ptr; ptr = (void *) &a; struct ABC *sptr; sptr = (struct ABC *) ptr; printf("a.x = %d\n", sptr->x ); printf("a.y = %d\n", sptr->y ); return 0; } .. _void_ptr_sp_ex_7: .. tab-set:: .. tab-item:: void pointer pointing to char array .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow void pointer can hold the address of a character array * Step 1 : Define a single dimension array of characters .. code-block:: c char a[7] = "Laptop"; * Step 2 : Define a void pointer and assign address of array to it .. code-block:: c void *ptr; ptr = (void *) a; * Step 3 : Access and Print the String : Typecasting method .. code-block:: c printf("a = %s\n", (char *)ptr); * Step 4 : Access and Print the String : Separate pointer method .. code-block:: c char *cptr; cptr = (char *) ptr; printf("a = %s\n", cptr); * Step 5 : Access and Print individual characters : Typecasting method .. code-block:: c for (int i = 0; i < 7; i++) { printf("%c", ((char *)ptr)[i] ); } * Step 6 : Access and Print individual characters : Separate pointer method .. code-block:: c char *ch_ptr; ch_ptr = (char *) ptr; for (int i = 0; i < 7; i++) { printf("%c", ch_ptr[i] ); } * See full program below .. code-block:: c :linenos: #include int main(void) { char a[7] = "Laptop"; void *ptr; ptr = (void *) a; // Method 1 : Print String : Use Typecasting printf("a = %s\n", (char *)ptr); // Method 2 : Print String : Use Seprate pointer char *cptr; cptr = (char *) ptr; printf("a = %s\n", cptr); // Method 1 : Print Character : Use Typecasting for (int i = 0; i < 7; i++) { printf("%c", ((char *)ptr)[i] ); } printf("\n"); // Method 2 : Print Character : Use Separate pointer char *ch_ptr; ch_ptr = (char *) ptr; for (int i = 0; i < 7; i++) { printf("%c", ch_ptr[i] ); } printf("\n"); return 0; } .. _void_ptr_sp_ex_8: .. tab-set:: .. tab-item:: void pointer pointing to int array .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow void pointer can hold the address of an integer array * Step 1 : Define a single dimension array of integers .. code-block:: c int a[7] = { 0, 1, 2, 3, 4, 5, 6 }; * Step 2 : Define a void pointer and assign address of array to it .. code-block:: c void *ptr; ptr = (void *) a; * Step 3 : Access and Print individual integers : Typecasting method .. code-block:: c for (int i = 0; i < 7; i++) { printf("%d ", ((int *)ptr)[i] ); } * Step 4 : Access and Print individual integers: Separate pointer method .. code-block:: c int *i_ptr; i_ptr = (int *) ptr; for (int i = 0; i < 7; i++) { printf("%d ", i_ptr[i] ); } * See full program below .. code-block:: c :linenos: #include int main(void) { int a[7] = { 0, 1, 2, 3, 4, 5, 6 }; void *ptr; ptr = (void *) a; // Method 1 : Print Integers : Typecasting method for (int i = 0; i < 7; i++) { printf("%d ", ((int *)ptr)[i] ); } printf("\n"); // Method 2 : Print Integers : Separate Pointer method int *i_ptr; i_ptr = (int *)ptr; for (int i = 0; i < 7; i++) { printf("%d ", i_ptr[i] ); } printf("\n"); return 0; } * Output is as below .. code-block:: c 0 1 2 3 4 5 6 0 1 2 3 4 5 6 .. _void_ptr_sp_ex_9: .. tab-set:: .. tab-item:: void pointer pointing to structure array .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow void pointer can hold the address of a structure array * Step 1 : Define a single dimension array of structures .. code-block:: c struct ABC { int x; int y; }; struct ABC a[3] = { { .x = 1, .y = 2 }, { .x = 10, .y = 20 }, { .x = 100, .y = 200 } }; * Step 2 : Define a void pointer and assign address of array to it .. code-block:: c void *ptr; ptr = (void *) a; * Step 3 : Access and Print individual structures : Typecasting method .. code-block:: c for (int i = 0; i < 3; i++) { printf("a[%d].x = %d\t", i, ((struct ABC *)ptr)[i].x ); printf("a[%d].y = %d ", i, ((struct ABC *)ptr)[i].y ); printf("\n"); } * Step 4 : Access and Print individual structures : Separate pointer method .. code-block:: c struct ABC *s_ptr; s_ptr = (struct ABC *) ptr; for (int i = 0; i < 3; i++) { printf("a[%d].x = %d\t", i, s_ptr[i].x ); printf("a[%d].y = %d ", i, s_ptr[i].y ); printf("\n"); } * See full program below .. code-block:: c :linenos: #include struct ABC { int x; int y; }; int main(void) { struct ABC a[3] = { { .x = 1, .y = 2 }, { .x = 10, .y = 20 }, { .x = 100, .y = 200 } }; void *ptr; ptr = (void *) a; // Method 1 : Print Integers : Typecasting method for (int i = 0; i < 3; i++) { printf("a[%d].x = %d\t", i, ((struct ABC *)ptr)[i].x ); printf("a[%d].y = %d ", i, ((struct ABC *)ptr)[i].y ); printf("\n"); } printf("\n"); // Method 2 : Print Integers : Separate Pointer method struct ABC *s_ptr; s_ptr = (struct ABC *) ptr; for (int i = 0; i < 3; i++) { printf("a[%d].x = %d\t", i, s_ptr[i].x ); printf("a[%d].y = %d ", i, s_ptr[i].y ); printf("\n"); } printf("\n"); return 0; } .. _void_ptr_sp_ex_10: .. tab-set:: .. tab-item:: Call by Value : ``void`` pointer .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow void pointer can be passed as an argument to a function (By Value) * Step 1 : Define an Integer .. code-block:: c int a = 5; * Step 2 : Define a ``void`` pointer and assign address of integer .. code-block:: c void *ptr; ptr = (void *) &a; * Step 3 : Pass ``ptr`` as call by Value to function ``fun`` .. code-block:: c fun(ptr); * Step 4 : Define function ``fun``. Note the prototype ! .. code-block:: c void fun(void *p) { } * Step 5 : Derefer and access integer inside function ``fun`` .. code-block:: c void fun(void *p) { int *iv; iv = (int *) p; printf("a = %d\n", *iv); } * See full program below .. code-block:: c :linenos: #include void fun(void *p) { int *iv; iv = (int *) p; printf("a = %d\n", *iv); } int main(void) { int a = 5; void *ptr; ptr = (void *) &a; fun(ptr); return 0; } .. _void_ptr_sp_ex_11: .. tab-set:: .. tab-item:: Call by Reference : ``void`` pointer .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow void pointer can be passed as an argument to a function (By Reference) * Step 1 : Define an Integer .. code-block:: c int a = 5; * Step 2 : Define a ``void`` pointer and assign address of integer .. code-block:: c void *ptr; ptr = (void *) &a; * Step 3 : Pass ``ptr`` as call by Reference to function ``fun`` .. code-block:: c fun(&ptr); * Step 4 : Define function ``fun``. Note the prototype ! .. code-block:: c void fun(void **p) { } * Step 5 : Derefer and access integer inside function ``fun`` .. code-block:: c void fun(void **p) { int *iv; iv = (int *) *p; printf("a = %d\n", *iv); } * See full program below .. code-block:: c :linenos: #include void fun(void **p) { int *iv; iv = (int *) *p; printf("a = %d\n", *iv); } int main(void) { int a = 5; void *ptr; ptr = (void *) &a; fun(&ptr); return 0; } .. _void_ptr_sp_ex_12: .. tab-set:: .. tab-item:: void pointer in expressions .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow void pointer can be used as part of an expression * Step 1 : Define an Integer .. code-block:: c int a = 10; * Step 2 : Define a void pointer ``ptr`` and assign address of integer to it .. code-block:: c void *ptr; ptr = (void *) &a; * Step 3 : Derefer void pointer ``ptr`` and use in an expression .. code-block:: c sum = *(int *)ptr + b + c; This is also same as .. code-block:: c sum = a + b + c; * See full program below .. code-block:: c :linenos: #include int main(void) { int a = 10; int b = 20; int c = 30; int sum; void *ptr; ptr = (void *) &a; sum = a + b + c; printf("sum = %d\n", sum); sum = *(int *)ptr + b + c; printf("sum = %d\n", sum); return 0; } .. _void_ptr_sp_ex_13: .. tab-set:: .. tab-item:: malloc with void pointer .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow void pointer can point to heap allocated memory * Step 1 : Define a void pointer ``ptr`` .. code-block:: c void *ptr; * Step 2 : Allocate memory from heap and assign to ``ptr`` .. code-block:: c ptr = malloc(40); * Step 3 : Assign void pointer to an integer pointer .. code-block:: c int *iptr; iptr = (int *) ptr; * Step 4 : Write : Use ``iptr`` to write to Heap memory .. code-block:: c for (int i = 0; i < 10; i++) { iptr[i] = ++count; } * Step 5 : Read : Use ``iptr`` to read from Heap memory .. code-block:: c for (int i = 0; i < 10; i++) { printf("%d\n", iptr[i]); } * See full program below .. code-block:: c :linenos: #include #include int main(void) { void *ptr; ptr = malloc(40); int *iptr; iptr = (int *) ptr; int count = 0; for (int i = 0; i < 10; i++) { iptr[i] = ++count; } for (int i = 0; i < 10; i++) { printf("%d\n", iptr[i]); } free(ptr); return 0; } .. _void_ptr_sp_ex_14: .. tab-set:: .. tab-item:: Array of void pointers : Basic Example .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow We can define an Array of void pointers * Step 1 : Define an array of void pointers .. code-block:: c void *ptr[4]; * Step 2 : Assign individual void pointers .. code-block:: c int a = 10; char b = 20; struct ABC c = { .x = 30, .y = 40 }; struct ABC d = { .x = 50, .y = 60 }; ptr[0] = (void *) &a; ptr[1] = (void *) &b; ptr[2] = (void *) &c; ptr[3] = (void *) &d.x; * Step 3 : Use the void pointers in an expression. Remember to Typecast and Derefer ! .. code-block:: c sum = *(int *)ptr[0] + *(char *)ptr[1] + ((struct ABC *)ptr[2]) -> x + ((struct ABC *)ptr[2]) -> y + *(int *)ptr[3]; This is same as .. code-block:: c sum = a + b + c.x + c.y + d.x; * See full program below .. code-block:: c :linenos: #include struct ABC { int x; int y; }; int main(void) { int a = 10; char b = 20; struct ABC c = { .x = 30, .y = 40 }; struct ABC d = { .x = 50, .y = 60 }; void *ptr[4]; ptr[0] = (void *) &a; ptr[1] = (void *) &b; ptr[2] = (void *) &c; ptr[3] = (void *) &d.x; int sum; sum = *(int *)ptr[0] + *(char *)ptr[1] + ((struct ABC *)ptr[2]) -> x + ((struct ABC *)ptr[2]) -> y + *(int *)ptr[3]; printf("sum = %d\n", sum); return 0; } .. _void_ptr_sp_ex_15: .. tab-set:: .. tab-item:: Array of void pointers : Call by Value .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Array of void pointers can be passed as an argument to a function (By Value) * Step 1 : Define an array of void pointers .. code-block:: c void *ptr[4]; * Step 2 : Assign individual void pointers .. code-block:: c int a = 10; char b = 20; struct ABC c = { .x = 30, .y = 40 }; struct ABC d = { .x = 50, .y = 60 }; ptr[0] = (void *) &a; ptr[1] = (void *) &b; ptr[2] = (void *) &c; ptr[3] = (void *) &d.x; * Step 3 : Pass array of void pointers by Value to function ``fun`` .. code-block:: c fun(ptr); * Step 4 : Define the function ``fun`` .. code-block:: c void fun(void *p[4]) { } * Step 5 : Use the void pointers in an expression. Remember to Typecast and Derefer ! .. code-block:: c void fun(void *p[4]) { int sum; sum = *(int *)p[0] + *(char *)p[1] + ((struct ABC *)p[2]) -> x + ((struct ABC *)p[2]) -> y + *(int *)p[3]; printf("sum = %d\n", sum); } * See full program below .. code-block:: c :linenos: #include struct ABC { int x; int y; }; void fun(void *p[4]) { int sum; sum = *(int *)p[0] + *(char *)p[1] + ((struct ABC *)p[2]) -> x + ((struct ABC *)p[2]) -> y + *(int *)p[3]; printf("sum = %d\n", sum); } int main(void) { int a = 10; char b = 20; struct ABC c = { .x = 30, .y = 40 }; struct ABC d = { .x = 50, .y = 60 }; void *ptr[4]; ptr[0] = (void *) &a; ptr[1] = (void *) &b; ptr[2] = (void *) &c; ptr[3] = (void *) &d.x; fun(ptr); return 0; } .. _void_ptr_sp_ex_16: .. tab-set:: .. tab-item:: Array of void pointers : Call by Reference .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Array of void pointers can be passed as an argument to a function (By Reference) * Step 1 : Define an array of void pointers .. code-block:: c void *ptr[4]; * Step 2 : Assign individual void pointers .. code-block:: c int a = 10; char b = 20; struct ABC c = { .x = 30, .y = 40 }; struct ABC d = { .x = 50, .y = 60 }; ptr[0] = (void *) &a; ptr[1] = (void *) &b; ptr[2] = (void *) &c; ptr[3] = (void *) &d.x; * Step 3 : Pass array of void pointers by Reference to function ``fun`` .. code-block:: c fun(&ptr); * Step 4 : Define the function ``fun`` .. code-block:: c void fun(void * (*p) [4]) { } * Step 5 : Use the void pointers in an expression. Remember to Typecast and Derefer ! .. code-block:: c void fun(void * (*p) [4]) { int sum; sum = *(int *)(*p)[0] + *(char *)(*p)[1] + ((struct ABC *)(*p)[2]) -> x + ((struct ABC *)(*p)[2]) -> y + *(int *)(*p)[3]; printf("sum = %d\n", sum); } * See full program below .. code-block:: c :linenos: #include struct ABC { int x; int y; }; void fun(void * (*p) [4]) { int sum; sum = *(int *)(*p)[0] + *(char *)(*p)[1] + ((struct ABC *)(*p)[2]) -> x + ((struct ABC *)(*p)[2]) -> y + *(int *)(*p)[3]; printf("sum = %d\n", sum); } int main(void) { int a = 10; char b = 20; struct ABC c = { .x = 30, .y = 40 }; struct ABC d = { .x = 50, .y = 60 }; void *ptr[4]; ptr[0] = (void *) &a; ptr[1] = (void *) &b; ptr[2] = (void *) &c; ptr[3] = (void *) &d.x; fun(&ptr); return 0; } .. _void_ptr_sp_ex_17: .. tab-set:: .. tab-item:: void pointer and nested structures .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow void pointers can be defined inside a structure * Step 1 : Define a structure ``struct ABC`` with a void pointer .. code-block:: c struct ABC { int a; int b; int c; void *pqr_ptr; }; * Step 2 : Define a structure ``struct PQR`` .. code-block:: c struct PQR { int p; int q; int r; }; * Step 3 : Define structue objects for ``struct ABC`` and ``struct PQR`` .. code-block:: c struct ABC abc = {.a = 10, .b = 20, .c = 30 }; struct PQR pqr = {.p = 100, .q = 200, .r = 300 }; * Step 4 : Assign void pointer inside ``struct ABC`` with address of ``struct PQR`` .. code-block:: c abc.pqr_ptr = (void *) &pqr; * Step 5 : Assign void pointer ``ptr`` with address of ``struct ABC`` .. code-block:: c ptr = (void *) &abc; * Step 6 : Pass ``ptr`` by Value to function ``fun`` .. code-block:: c fun(ptr); * Step 7 : Define the function ``fun`` .. code-block:: c void fun(void *ptr) { } * Step 8 : Use void pointers inside function ``fun``. Typecast and Derefer .. code-block:: c void fun(void *ptr) { struct ABC *abc_p; struct PQR *pqr_p; int sum; abc_p = (struct ABC *)ptr; pqr_p = (struct PQR *)abc_p->pqr_ptr; sum = abc_p->a + abc_p->b + abc_p->c ; sum += pqr_p->p + pqr_p->q + pqr_p->r; printf("sum = %d\n", sum); } * See full program below .. code-block:: c :linenos: #include struct PQR { int p; int q; int r; }; struct ABC { int a; int b; int c; void *pqr_ptr; }; void fun(void *ptr) { struct ABC *abc_p; struct PQR *pqr_p; int sum; abc_p = (struct ABC *)ptr; pqr_p = (struct PQR *)abc_p->pqr_ptr; sum = abc_p->a + abc_p->b + abc_p->c ; sum += pqr_p->p + pqr_p->q + pqr_p->r; printf("sum = %d\n", sum); } int main(void) { struct ABC abc = {.a = 10, .b = 20, .c = 30 }; struct PQR pqr = {.p = 100, .q = 200, .r = 300 }; abc.pqr_ptr = (void *) &pqr; void *ptr; ptr = (void *) &abc; fun(ptr); return 0; } .. tab-set:: .. tab-item:: Summary ================================================================================================= =========== Learnings ================================================================================================= =========== Single void pointer CAN NOT be dereferenced directly without explicit typecast Single void pointer CAN HOLD the address of a character Single void pointer CAN HOLD the address of an integer Single void pointer CAN HOLD the address of a structure Single void pointer CAN HOLD the address of a character array Single void pointer CAN HOLD the address of an integer array Single void pointer CAN HOLD the address of a structure array Single void pointer CAN BE passed by value to a function Single void pointer CAN BE passed by reference to a function Single void pointer CAN BE used in an expression with explicit typecasting Single void pointer CAN POINT to memory block in Heap Array of Single void pointers CAN BE defined which can hold addresses of heterogeneous types Array of Single void pointers CAN BE passed by value to a function Array of Single void pointers CAN BE passed by reference to a function Single void pointers CAN BE used as structure members ================================================================================================= =========== .. card:: See Also * Current Module * :doc:`void_ptr` * Previous Module * :doc:`../const_ptr/const_ptr` * Next Module * :doc:`../array_of_ptr/array_of_ptr` * Other Modules * :doc:`../variable_and_ptr/variable_and_ptr` * :doc:`../array_n_ptrs/array_n_ptrs` * :doc:`../malloc_ptr/malloc_ptr` * :doc:`../typecasting_n_ptr/typecasting_n_ptr` * :doc:`../funcs_n_ptrs/funcs_n_ptrs` * :doc:`../memcpy_ptr/memcpy_ptr` * :doc:`../ptr_to_array/ptr_to_array` * :doc:`../function_ptr/function_ptr` * :doc:`../pre_incr_ptr/pre_incr_ptr` * :doc:`../post_incr_ptr/post_incr_ptr` * :doc:`../pre_decr_ptr/pre_decr_ptr` * :doc:`../post_decr_ptr/post_decr_ptr`