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.
Program/Source Code:
The source code to return multiple values from the function is given below. The given program is compiled and executed successfully.
Output:
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