ADVERTISEMENT
ADVERTISEMENT

Rust program to return multiple values from the function

Rust Function | Returning multiple values: Write an example to demonstrate the example of returning multiple values from the function.
Submitted by Nidhi, on October 09, 2021

Problem Solution:

In this program, we will create a user-defined function to return multiple values to the calling function.

Program/Source Code:

The source code to return multiple values from the function is given below. The given program is compiled and executed successfully.

// Rust program to return multiple values 
// from the function

fn myfun()->(i32,i32){
    return (10,20);
}

fn main() {
    let (num1,num2)=myfun();
    
    println!("Num1: {}",num1);
    println!("Num2: {}",num2);
}

Output:

Num1: 10
Num2: 20

Explanation:

In the above program, we created two functions myfun() and main(). The myfun() function is a user-defined function that returns two integer values to the calling function.

In the main() function, we called the myfun() function and get two integer numbers, and printed them.

Rust Functions Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.