fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //By FreeNickname
  5. //http://stackoverflow.com/questions/30581200/how-to-dereference-a-n-levels-void-pointer-to-an-int-pointer/30581819#30581819
  6.  
  7. int foo(void *p, unsigned int n) {
  8. for (unsigned int i = 0; i < n; ++i) {
  9. p = *((void**)p);
  10. }
  11. return (int)p;
  12. }
  13.  
  14. int main()
  15. {
  16. int a = 7;
  17. int *p1 = &a;
  18. int **p2 = &p1;
  19. int ***p3 = &p2;
  20.  
  21. std::cout<<"result: "<<foo(p3, 3);
  22.  
  23.  
  24. // your code goes here
  25. return 0;
  26. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
result: 7