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 Apr 8, 2014 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 Apr 8, 2014 by sara Guru (24,570 points)

Related questions

0 votes
2 answers 200 views
200 views asked Jul 10, 2011 by allison Sr Member (1,490 points)
0 votes
1 answer 59 views
59 views asked May 31, 2011 by carlton Sr Member (3,990 points)
0 votes
1 answer 12 views
12 views asked Dec 27, 2013 by smith Geek (15,340 points)
0 votes
1 answer 26 views
26 views asked Apr 8, 2014 by sara Guru (24,570 points)
0 votes
1 answer 29 views
29 views asked Apr 8, 2014 by rock Expert (14,990 points)
...