| Forums.Sureshkumar.net : A Perfect Place to Share Knowledge Blogs Games Magazines |
|
|||||||
| ds. c , c++ Interview / Technical Questions Kindly solve an many as questions you can. It will sharpen your skills and those solutions will help others too. |
![]() |
|
|
LinkBack | Thread Tools | Rate Thread | Display Modes |
|
|
#2 (permalink) |
|
Moderator
Join Date: Jul 2006
Posts: 2,184
Thanks: 5 Thanked 372 Times in 255 Posts Thanks: 5
Thanked 372 Times in 255 Posts
Rep Power: 59
|
Re: what is void pointer
void pointers
The void type of pointer is a special type of pointer. In C++, void represents the absence of type, so void pointers are pointers that point to a value that has no type (and thus also an undetermined length and undetermined dereference properties). This allows void pointers to point to any data type, from an integer value or a float to a string of characters. But in exchange they have a great limitation: the data pointed by them cannot be directly dereferenced (which is logical, since we have no type to dereference to), and for that reason we will always have to cast the address in the void pointer to some other pointer type that points to a concrete data type before dereferencing it. One of its uses may be to pass generic parameters to a function: // increaser #include <iostream> using namespace std; void increase (void* data, int psize) { if ( psize == sizeof(char) ) { char* pchar; pchar=(char*)data; ++(*pchar); } else if (psize == sizeof(int) ) { int* pint; pint=(int*)data; ++(*pint); } } int main () { char a = 'x'; int b = 1602; increase (&a,sizeof(a)); increase (&b,sizeof(b)); cout << a << ", " << b << endl; return 0; } y, 1603 sizeof is an operator integrated in the C++ language that returns the size in bytes of its parameter. For non-dynamic data types this value is a constant. Therefore, for example, sizeof(char) is 1, because char type is one byte long.
__________________
Kiran |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Bob Technologies placement paper 2 | sridhar | BOB TECHNOLOGIES Placement Papers | 0 | 03-02-07 07:43 PM |
| Bob Technologies placement paper 1 | sridhar | BOB TECHNOLOGIES Placement Papers | 0 | 03-02-07 07:42 PM |
| C language - What is a void pointer? | GEEK | ds. c , c++ Interview / Technical Questions | 1 | 23-01-07 04:34 PM |
| C language - Can math operations be performed on a void pointer? | GEEK | ds. c , c++ Interview / Technical Questions | 0 | 23-01-07 01:34 PM |
| Help me for Interview question | ajutipu | EMBEDED SYSTEMS & VLSI | 4 | 31-08-06 08:04 PM |