C Books Guide and List
C++ Books Guide and List
Best Java Books

3,749 questions

4,049 answers

114 comments

10,705 users

What is a void pointer?

0 votes
25 views
asked by sunny Expert (11,410 points)

1 Answer

0 votes
A void pointer is a C convention for a raw address. The compiler has no idea what type of object a void Pointer really points to. If you write
int *ip;
ip points to an int. If you write
void *p;
p doesn’t point to a void!
In C and C++, any time you need a void pointer, you can use anotherpointer type. For example, if you have a char*, you can pass it to afunction that expects a void*. You don’t even need to cast it. In C (butnot in C++), you can use a void* any time you need any kind of pointer, without casting. (In C++, you need to cast it).
A void pointer is used for working with raw memory or for passing a pointer to an unspecified type.
Some C code operates on raw memory. When C was first invented, character pointers (char *) were used for that. Then people startedgetting confused about when a character pointer was a string, when it was a character array, and when it was raw memory.
answered by sara Guru (24,570 points)

Related questions

0 votes
2 answers 202 views
202 views asked by allison Sr Member (1,490 points)
0 votes
1 answer 59 views
59 views asked by carlton Sr Member (3,990 points)
0 votes
1 answer 15 views
0 votes
1 answer 27 views
0 votes
1 answer 30 views
30 views asked by rock Expert (14,990 points)
...