Q:

Rust program to return multiple values from the function

belongs to collection: Rust Functions Programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Rust program to demonstrate the recursion... >>
<< Rust program to return a structure from the functi...