fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <cctype>
  5. #include <cstdlib>
  6. #include <stdexcept>
  7. #include <initializer_list>
  8.  
  9. using namespace std;
  10.  
  11. using string_arr = string[10];
  12.  
  13. string s[10] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"};
  14. int odd[] = {1, 3, 5, 7};
  15. int even[] = {0, 2, 4, 6};
  16.  
  17. string (&f())[10]
  18. {
  19. return s;
  20. }
  21.  
  22. string_arr& f1() { return s; }
  23.  
  24. auto f2() -> string_arr&
  25. {
  26. return s;
  27. }
  28.  
  29. decltype(s) &f3() { return s; }
  30.  
  31. decltype(odd) &g(int i)
  32. {
  33. return (i % 2) ? even : odd;
  34. }
  35.  
  36.  
  37. int main(int argc, char *argv[])
  38. {
  39. string (&x)[10] = f3();
  40. int (&y)[4] = g(2);
  41.  
  42. for (const auto i : x) cout << i << " ";
  43. cout << endl;
  44. for (const auto i : y) cout << i << endl;
  45. }
  46.  
  47.  
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
a b c d e f g h i j 
1
3
5
7