fork download
  1.  
  2. #include <iostream>
  3.  
  4. // Gibt eine Referenz auf ein 3-Array von ints zurück
  5. int (& getThreeInts()) [3]
  6. {
  7. static int theInts[3] = { 1, 2, 3 };
  8. return theInts;
  9. }
  10.  
  11. int main(int argc, char * argv[])
  12. {
  13. // Falsch: Ist ein 3-Array von Referenzen
  14. // int & (k[3]) = getThreeInts();
  15.  
  16. // Korrekt: Initialisiere Referenz auf ein 3-Array von ints
  17. int (& i)[3] = getThreeInts();
  18.  
  19. std::cout << i[0] << " " << i[1] << " " << i[2] << std::endl;
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 2884KB
stdin
Standard input is empty
stdout
1 2 3