Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ program for void pointers

#include<iostream>
using namespace std;
void print(void* ptr, char type) {
	switch (type)
	{
	case'i': {
		cout << *((int*)ptr) << endl;
	}break;
	case'c': {
		cout << *((char*)ptr) << endl;
	}break;
	}
}
int main() {
							/*void pointers can hold the
							values of other variable like char, int, foat
							limitation: Is that u can not
							directly dereference a void pointer*/
	int num = 5;
	char let = 'b';
	print(&num, 'i');
	print(&let, 'c');

	return 0;
}
Source by www.atnyla.com #
 
PREVIOUS NEXT
Tagged: #program #void #pointers
ADD COMMENT
Topic
Name
3+9 =