#include <iostream>
using namespace std;

//By FreeNickname
//http://stackoverflow.com/questions/30581200/how-to-dereference-a-n-levels-void-pointer-to-an-int-pointer/30581819#30581819

int foo(void *p, unsigned int n) {
	for (unsigned int i = 0; i < n; ++i) {
		p = *((void**)p);
	}
	return (int)p;
}

int main()
{
	int a = 7;
	int *p1 = &a;
	int **p2 = &p1;
	int ***p3 = &p2;
	
	std::cout<<"result: "<<foo(p3, 3);
	
	
	// your code goes here
	return 0;
}