1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
void printValue(void* ptr, char type) {
switch(type) {
case 'i':
std::cout << "Integer value: " << *static_cast<int*>(ptr) << std::endl;
break;
case 'd':
std::cout << "Double value: " << *static_cast<double*>(ptr) << std::endl;
break;
case 'c':
std::cout << "Char value: " << *static_cast<char*>(ptr) << std::endl;
break;
}
}
int main() {
int i = 5;
double d = 3.14;
char c = 'A';
printValue(&i, 'i');
printValue(&d, 'd');
printValue(&c, 'c');
return 0;
}
Back to void