Answers for "c++ can you return multiple values from function"

C++
5

c++ return multiple values

#include <tuple>

std::tuple<int, int> divide(int dividend, int divisor) {
    return  std::make_tuple(dividend / divisor, dividend % divisor);
}

#include <iostream>

int main() {
    using namespace std;

    int quotient, remainder;

    tie(quotient, remainder) = divide(14, 3);

    cout << quotient << ',' << remainder << endl;
}
Posted by: Guest on May-16-2020
0

accepting multiple values from a function in cpp

#include<iostream>
using namespace std;
void div(int a, int b, int "ient, int &remainder) {
   quotient = a / b;
   remainder = a % b;
}
main() {
   int a = 76, b = 10;
   int q, r;
   div(a, b, q, r);
   cout << "Quotient is: "<< q <<"nRemainder is: "<< r <<"n";
}
Posted by: Guest on April-24-2021

Code answers related to "c++ can you return multiple values from function"

Browse Popular Code Answers by Language