0

How can I assign array of two elements to two variables?

Here is example of my idea (no valid code):

getTwoValues() {
    int a = 7;
    int b = 5;
    return {a, b};
}

int x, y = getTwoValues();

// Expected output: x = 7, y = 5
  • 2
    The top answer on the post has what you really want: [structured bindings](https://en.cppreference.com/w/cpp/language/structured_binding) – NathanOliver Jan 13 '20 at 21:58
  • TLDR; `getTwoValues() {` => `auto getTwoValues() {` and `int x, y = getTwoValues();` => `auto [x, y] = getTwoValues();` – Thomas Sablik Jan 13 '20 at 22:16

0 Answers0