What is a void pointer?

Questions by mitulgolakiya

Showing Answers 1 - 3 of 3 Answers

aldoboyzzz

  • Jul 19th, 2008
 

a pointer with no return type is called a null pointer.It may be any kind of datatype.It takes the data type according to the requirement in the program.

for eg:



 #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;
}

bputhal

  • Mar 25th, 2009
 

void is generic pointer.Example
void * vp;
int *ip;
char * cp;
vp = ip;//ok
vp = cp;
But viceversa not allowed.ie ip = vp; not allowed

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions