GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Concepts  >  Data Structures

 Print  |  
Question:  What is a void pointer?



July 07, 2008 01:34:49 #1
 aldoboyzzz   Member Since: July 2008    Total Comments: 1 

RE: What is a void pointer?
 

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

     

 

Back To Question