Preview:
#include<iostream>
using namespace std;
void printData(void *ptr, char dataType){
  switch (dataType)
  {
    case 'i':
      cout << *((int *)ptr) << endl;
      break;

    case 'c':
      cout << *(static_cast<char *>(ptr)) << endl;
      break;
  }
}
int main(){
  int n = 7;
  char b = 'b';
  printData(&n, 'i');
  printData(&b, 'c');
  return 0;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter