- #include <iostream>
- // Void pointer can be pointed to any data type
- void print(void *ptr, char type)
- {
- switch (type)
- {
- case 'i':
- std::cout << (*(int *)ptr) << std::endl;
- break; //handle *int
- case 'c':
- std::cout << (*(char *)ptr) << std::endl; //handle *char
- break;
- }
- }
|