🌐
GeeksforGeeks
geeksforgeeks.org › c language › void-pointer-c-cpp
void Pointer in C - GeeksforGeeks
A void pointer can hold the address of variables of any data type. Before accessing the value stored at a void pointer, it must be explicitly typecast to the appropriate pointer type. Example: The following program demonstrates that a void pointer can store the address of different data types
Published: July 4, 2026
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_void_pointer.htm
void Pointer in C
Address of 'a': 853377452 Void pointer points to: 853377452 Address of 'b': 853377451 Void pointer points to: 853377451 · We can declare an array of void pointers and store pointers to different data types.
Discussions

Concept of void pointer in C programming - Stack Overflow
I think GCC treats arithmetic on void * pointers the same as char *, but it's not standard and you shouldn't rely on it. 2009-03-30T17:40:20.377Z+00:00 ... I'm not sure I follow. In example that OP listed above the incoming types are guaranteed to be correct by the user of the function. More on stackoverflow.com
🌐 stackoverflow.com
void pointers
A void* may point to anything you imagine. That's why C APIs are sometimes swimming in void*. You can also cast a function pointer to a void*. In C this is useful for the qsort() function. int compare(const void* obj1, const void* obj2) { const char* t1 = (const char*)obj1; const char* t2 = (const char*)obj2; return strcmp(str1, str2); } const char* array_of_string[] = {"qwe", "asd", "zxc"}; qsort(array_of_string, sizeof(array_of_string)/sizeof(array_of_string), compare); Now the above is fine C, but is terrible C++. In C++ void* is really not that useful. The above sort could be rewritten as: std::array array_of_string{"qwe", "asd", "zxc"}; std::ranges::sort(array_of_string); More on reddit.com
🌐 r/cpp_questions
30
20
October 13, 2020
What is the preferred way of doing generics in C?
How do popular projects like Linux, QEMU do it? Those specific projects? They don't. They have no need for them. QEMU does use some of glib's type-agnostic container types. But those aren't "generics" in the sense you're using the term: there is no specialisation of code based on the types involved. More on reddit.com
🌐 r/C_Programming
26
30
November 1, 2021
Initialization of 'Example *' from incompatible pointer type 'struct Example *'
There is no such thing as struct Pager defined in your program. You have defined a type named Pager, yes, but struct Pager is never explicitly defined. For example, there is the type U here, but no such thing as "struct U". typedef struct { // ... } U; This below, there is the type U and the type struct X. They have the same underlying representation. typedef struct X { // ... } U; With that, it naturally follows that this below allows for the type U and struct U. typedef struct U { // ... } U; This also could mean that struct U and U could refer to completely different types. struct U { // ... }; typedef int U; And as far as I understand it, you do not have "circular dependency". All you did was just split up your program in an inconvenient manner. More on reddit.com
🌐 r/C_Programming
6
4
December 15, 2023
People also ask

Is there any difference between the null pointer and the void pointer in C?
The null pointer is basically used in a program to assign the value 0 to a pointer variable of any data type. The void pointer, on the other hand, has no value assigned to it and we use it to store the addresses of other variables in the program- irrespective of their data types.
🌐
byjus.com
byjus.com › gate › void-pointer-in-c
Void Pointer in C
Why do we use a void pointer in C programs?
We use the void pointers to overcome the issue of assigning separate values to different data types in a program. The pointer to void can be used in generic functions in C because it is capable of pointing to any data type. One can assign the void pointer with any data type’s address, and then assign the void pointer to any pointer without even performing some sort of explicit typecasting. So, it reduces complications in a code.
🌐
byjus.com
byjus.com › gate › void-pointer-in-c
Void Pointer in C
What is the difference between a general pointer and a void pointer in C?
They are both the same. The void pointer in C is a pointer that is not associated with any data types. It points to some data location in the storage. This means it points to the address of variables. It is also called the general purpose pointer. In C, malloc() and calloc() functions return void * or generic pointers.
🌐
byjus.com
byjus.com › gate › void-pointer-in-c
Void Pointer in C
🌐
HackerEarth
hackerearth.com › practice › notes › void-pointer-in-c
void pointer in C | HackerEarth
A void pointer is a pointer that has no associated data type with it. A void pointer can hold address of any type and can be typcasted to any type. int a = 10; char b = 'x'; void *p …
🌐
Unstop
unstop.com › home › blog › void pointer in c explained in detail with code examples
Void Pointer In C Explained In Detail With Code Examples
March 1, 2024 - This method involves merely declaring the pointer variable with the syntax void * type. Here, we do not assign any specific location to the pointer. This is why the process if referred to as defining a void pointer in C without initializing it. It is useful if we want to assign an address at a later time, as we did in the example before.
🌐
Scaler
scaler.com › home › topics › void pointer in c
Void Pointer in C - Scaler Topics
October 13, 2023 - This means if we declare an int pointer then this pointer cannot point to, or store the address of floating-point or char variables, it can store the address of an integer variable only · The concept of void pointer here is, we declare a pointer to point to void, meaning a generic pointer, a pointer that has no data type associated with its own, which can point to any data type and can store any datatype's address as will be required
🌐
EDUCBA
educba.com › home › software development › software development tutorials › c programming tutorial › void pointer in c
Void Pointer in C | Examples on How Void Pointer Work in C?
April 3, 2023 - The syntax flow follows in a way that keyword void is the type of pointer followed by the name of the pointer which is being pointed and allocated as an address allocation. The Pointer declaration is performed with the pointer name and the pointer type supporting any data type. Representation of pointer in terms of C is the same as the pointer of character type. ... This example shows that the pointer is expecting a void type of pointer and then it is being pointed by the pointer whose name is given as ptra inclusive of ‘*’ symbol which denotes that a pointer is being declared and will be used in mere future for dereferencing purpose.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
GNU
gnu.org › software › c-intro-and-ref › manual › html_node › Void-Pointers.html
Void Pointers (GNU C Language Manual)
{ int *p; /* Converts return value ... has a pointer type also converts. For example, supposing the function hack is declared to require type float * for its parameter, this call to hack will convert the argument to that type....
Find elsewhere
🌐
BYJUS
byjus.com › gate › void-pointer-in-c
Void Pointer in C
August 1, 2022 - Here, the void keyword acts as the pointer type, and it is followed by the pointer name- to which the pointer type points and allocates the address location in the code. The declaration of a pointer happens with the name and type of pointer that supports any given data type. Let us take a look at an example ...
🌐
OverIQ
overiq.com › c-programming-101 › void-pointers-in-c
Void Pointers in C - C Programming Tutorial - OverIQ.com
For example: In the above snippet void pointer vp is pointing to the address of integer variable a. So in this case vp is acting as a pointer to int or (int *).
🌐
Medium
medium.com › @ayushkapri.richard › generic-pointers-void-pointers-in-c-c-8541d51bea3e
Generic Pointers (Void Pointers) in C / C++. | by Ayush Kapri | Medium
May 4, 2024 - Pointer arithmetic on void pointer can’t be done. // Example 1: int a = 1; void *ptr = &a; ptr++; // invalid // Example 2: float a2 = 1.0; void *ptr = &a2; (float*)ptr = (float*)ptr + 1; // valid: Pointer arthematic.
🌐
Javatpoint
javatpoint.com › void-pointer-in-c
Void Pointer in C - javatpoint
% -> . # Show Answer The correct option is (b). Explanation: For a structure, Arrow ( ->) is used... ... What is a Null Pointer? A Null Pointer is a pointer that does not point to any memory location. It stores the base address of the segment. The null pointer basically stores the Null value while void is the type of the pointer.
🌐
Dot Net Tutorials
dotnettutorials.net › home › void pointer in c
Void Pointer in C Language with Examples - Dot Net Tutorials
November 17, 2023 - Interfacing with System Calls or ... data types generically. For example, the qsort() function in the C standard library uses void pointers to sort arrays of any data type....
🌐
Sankalandtech
sankalandtech.com › Tutorials › C › void-pointer-c.html
void Pointers in C programming.
In this example, we first assign the address of the integer variable `n` to the void pointer `vd_ptr`. To derefer to a void pointer and access the value of `n`, we typecast the integer pointer `intPtr` before dereferencing the void pointer with `*intPtr`. This allows us to properly access the value stored at the memory location pointed to by the void pointer. In C programming, void pointers cannot be used directly for arithmetic operations because the compiler has no information about the size or type of the data they point to.
🌐
Testbook
testbook.com › home › gate › understanding void pointer in c programming - testbook.com
Understanding Void Pointer in C Programming - Testbook.com
In this syntax, the void keyword functions as the pointer type, followed by the pointer name, which the pointer type points to and allocates the address location in the code. The declaration of a pointer takes place with the name and type of pointer that supports any given data type. Here's an example for better understanding:
🌐
CodeWithHarry
codewithharry.com › tutorial › c-void-pointer
VOID Pointer | C Tutorial | CodeWithHarry
In this example, the void pointer’s data type gets typecasted to char as we have stored the address of a character value in it.
🌐
Tpoint Tech
tpointtech.com › void-pointer-in-c
void pointer in C - Tpoint Tech
June 16, 2026 - A void pointer is declared by using the void keyword followed by an asterisk (*) and the pointer name. The following syntax is used to declare a void pointer: ... The pointer can store the address of any data type.
Top answer
1 of 16
101

Is it possible to dereference the void pointer without type-casting in C programming language...

No, void indicates the absence of type, it is not something you can dereference or assign to.

is there is any way of generalizing a function which can receive pointer and store it in void pointer and by using that void pointer we can make a generalized function..

You cannot just dereference it in a portable way, as it may not be properly aligned. It may be an issue on some architectures like ARM, where pointer to a data type must be aligned at boundary of the size of data type (e.g. pointer to 32-bit integer must be aligned at 4-byte boundary to be dereferenced).

For example, reading uint16_t from void*:

/* may receive wrong value if ptr is not 2-byte aligned */
uint16_t value = *(uint16_t*)ptr;
/* portable way of reading a little-endian value */
uint16_t value = *(uint8_t*)ptr
                | ((*((uint8_t*)ptr+1))<<8);

Also, is pointer arithmetic with void pointers possible...

Pointer arithmetic is not possible on pointers of void due to lack of concrete value underneath the pointer and hence the size.

void* p = ...
void *p2 = p + 1; /* what exactly is the size of void?? */
2 of 16
33

In C, a void * can be converted to a pointer to an object of a different type without an explicit cast:

void abc(void *a, int b)
{
    int *test = a;
    /* ... */

This doesn't help with writing your function in a more generic way, though.

You can't dereference a void * with converting it to a different pointer type as dereferencing a pointer is obtaining the value of the pointed-to object. A naked void is not a valid type so derefencing a void * is not possible.

Pointer arithmetic is about changing pointer values by multiples of the sizeof the pointed-to objects. Again, because void is not a true type, sizeof(void) has no meaning so pointer arithmetic is not valid on void *. (Some implementations allow it, using the equivalent pointer arithmetic for char *.)

🌐
PiEmbSysTech
piembsystech.com › home › void pointer in c/c++/embedded c
Void Pointer In C/C++/Embedded C - PiEmbSysTech - Embedded Systems & VLSI Lab
September 15, 2021 - The Void Pointer can not be used for arithmetic operations due to its concrete size. But in the GNU C library, it is allowed by considering the size of the void is 1. For example, the following program compiles and runs fine in the GCC compiler.
🌐
Mirzafahad
mirzafahad.github.io › 2018-03-25-void-pointer
Void Pointer in C
March 25, 2018 - Let’s think of a very simple example. Assume we have a function called animal_sound(args), whose job is to generate animal sound based on it’s argument. Now, let’s say, we have a “dog” variable of type sDog_t and a “cat” variable of type sCat_t (sDog_t and sCat_t are typedefs). How do we make animal_sound() function to take both types of variables and not complain? void pointer to the rescue.
🌐
Electro4u
electro4u.net › blog › what-is-a-void-pointer-72
Void pointer in C/C++: Definition, uses, and examples - Electro4u.net
Declaration: void *ptr; declares a void pointer named ptr. Assignment: ptr = &num; assigns the address of the integer num to ptr. Typecasting and Dereferencing: *(int*)ptr typecasts ptr to an integer pointer and dereferences it to access the integer value. Similar operations: The same process ...