std::tuple, std::pair | Returning multiple values from a function using Tuple and Pair in C++ Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 63 Likes Like Report There can be some instances where you need to return multiple values (maybe of different data types ) while solving a problem. One method to do the same is by using pointers, structures or global variables, already discussed here There is another interesting method to do the same without using the above methods, using tuples (for returning multiple values ) and pairs (for two values). We can declare the function with return type as pair or tuple (whichever is required) and can pack the values to be returned and return the packed set of values. The returned values can be unpacked in the calling function. Tuple A tuple is an object capable to hold a collection of elements where each element can be of a different type. Class template std::tuple is a fixed-size collection of heterogeneous values Pair This class couples together a pair of values, which may be of different types A pair is a specific case of a std::tuple with two elements Note : Tuple can also be used to return two values instead of using pair . Cpp #include<bits/stdc++.h> using namespace std; // A Method that returns multiple values using // tuple in C++. tuple<int, int, char> foo(int n1, int n2) { // Packing values to return a tuple return make_tuple(n2, n1, 'a'); } // A Method returns a pair of values using pair std::pair<int, int> foo1(int num1, int num2) { // Packing two values to return a pair return std::make_pair(num2, num1); } int main() { int a,b; char cc; // Unpack the elements returned by foo tie(a, b, cc) = foo(5, 10); // Storing returned values in a pair pair<int, int> p = foo1(5,2); cout << "Values returned by tuple: "; cout << a << " " << b << " " << cc << endl; cout << "Values returned by Pair: "; cout << p.first << " " << p.second; return 0; } Output: Values returned by tuple: 10 5 a Values returned by Pair: 2 5 Create Quiz Comment K kartik 63 Improve K kartik 63 Improve Article Tags : C++ STL CPP-Functions Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like