fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct elem {
  6. int key;
  7. int number;
  8. };
  9.  
  10. void func(elem** arr, elem* q, int i) {
  11. arr[i] = q;
  12. }
  13.  
  14.  
  15. int main() {
  16. int n = 4;
  17. elem** arr = new elem*[n];
  18. elem q = { 2,0 }; elem w = { 5,1 }; elem e = { 10,4 }; elem r = { 54,5 };
  19. func(arr, &q, 0);
  20. func(arr, &w, 1);
  21. func(arr, &e, 2);
  22. func(arr, &r, 3);
  23. for (int i = 0; i < n; i++)
  24. cout << i << ": " << arr[i]->key << endl;
  25. return 0;
  26. }
Success #stdin #stdout 0s 4312KB
stdin
Standard input is empty
stdout
0: 2
1: 5
2: 10
3: 54