Javatpoint Logo
Javatpoint Logo

Returning Multiple Values from a Function using Tuple and Pair in C++

We may have encountered scenarios where, while working on functions which might have a single part where the return type is only a single data type, we require to return multiple data types. To solve this issue, we are learning the concept of Returning various values from a function using Tuple and Pair in C++.

Tuples and Pairs in C++

It is an object that holds the units or elements of any data type. The Tuple data type class size in C++ programming language std::tuple is fixed. Pairs in C++ are

C++ code to Demonstrate Tuples

Output:

values of the Tuple during the initial stage are as follows: z 20 85.5
values of the Tuple after the modification stage are as follows: b 20 20.5

C++ Code to Demonstrate Pairs

Output:

41 62
63 62
103 44 n

C++ code Returning Multiple Values from a Function using Tuple and Pair.

Output:

The values returned by the Tuple are as follows: 110 15 a
The values returned by the Pair are as follows: 32 25






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA