fork download
  1. // I know this is technically supposed to be C code. Please indulge me using cout to output the numbers, don't feel like using printf right now
  2.  
  3. #include <iostream>
  4. #include <stdlib.h>
  5.  
  6. struct Test; // This is a forward declaration so that the typedef won't throw a warning
  7. typedef Test* test_array;
  8.  
  9. struct Test {
  10. int value;
  11. Test *parent;
  12. test_array *child;
  13. };
  14.  
  15. int main()
  16. {
  17. Test *first = (Test *)malloc(sizeof(Test));
  18. Test *second = (Test *)malloc(sizeof(Test));
  19. Test *third = (Test *)malloc(sizeof(Test));
  20.  
  21. first->child = (test_array *)malloc(sizeof(test_array *) * 2);
  22.  
  23. first->child[0] = second;
  24. first->child[1] = third;
  25.  
  26. second->value = 2;
  27. third->value = 3;
  28.  
  29. std::cout << first->child[0]->value << first->child[1]->value;
  30.  
  31. // Let's clean up after ourselves!
  32. free(second);
  33. free(third);
  34. free(first->child);
  35. free(first);
  36. }
Success #stdin #stdout 0.02s 2856KB
stdin
Standard input is empty
stdout
23