C++ Pointer to type void

Description

C++ Pointer to type void

#include <iostream>
using namespace std;
int main()//w  w  w .j  av  a 2  s .  c  o m
{
   int intvar;
   float flovar;
   int* ptrint;               //define pointer to int
   float* ptrflo;             //define pointer to float
   void* ptrvoid;             //define pointer to void
   ptrint = &intvar;          //ok, int* to int*
   // ptrint = &flovar;          //error, float* to int*
   // ptrflo = &intvar;          //error, int* to float*
   ptrflo = &flovar;          //ok, float* to float*
   ptrvoid = &intvar;         //ok, int* to void*
   ptrvoid = &flovar;         //ok, float* to void*
   return 0;
}



PreviousNext

Related