Can C++ make a function that returns two values ?
touqra
0
Newbie Poster
Recommended Answers
Jump to PostNo you cannot. But you can pass the variables by reference so that the changes are reflected in the original variables. For example
void test(int &a,int &b) { a=a+1; b=b+1; } int main() { int c=23,d=6; test(c,d); cout<<c<<endl<<d; cin.get(); cin.ignore(); return 0; }
Here the values of …
Jump to Postc++98 has the convenient
std::pair<>
.
c++09 also hasstd::tuple<>
.#include <utility> #include <algorithm> #include <tuple> std::pair<int,int> min_n_max( const int* arr, std::size_t N ) { // invariant: N > 0 int low = arr[0] ; int high = arr[0] ; for( std::size_t i=1 ; …
All 6 Replies
hammerhead
19
Posting Whiz in Training
twomers
408
Posting Virtuoso
Radical Edward
301
Posting Pro
vijayan121
1,152
Posting Virtuoso
touqra
0
Newbie Poster
vijayan121
1,152
Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.