Tuesday, November 1, 2011

Program Pointer


Contoh program pointer

#include <iostream>  
using namespace std;  

enum Type  {  
   INT,  
   FLOAT,  
   STRING,  
 };  

void Display(void *pVoid, Type eType)  {    
   switch (eType)  {  
 case INT:  
   cout << *(int*)pVoid << endl;  
  break;  
 case FLOAT:  
  cout << *(float*)pVoid << endl;  
  break;  
 case STRING:  
  cout << (char*)pVoid << endl;  
  break;  
   }  
}    

int main()  
{  
   int a = 10;  
   float b = 987.654;  
   char *c = 
 "Art is a lie that makes us realize the truth.";  
   Display(&a, INT);  
   Display(&b, FLOAT);  
   Display(c, STRING);  
   return 0;  
} 

Artikel Terkait



0 komentar:

Lorem Ipsum

Lorem Ipsum




Lorem

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP