Q:

Rust program to pass a tuple as a parameter

belongs to collection: Rust Tuples Programs

0

In this program, we will create a function with a tuple as a parameter. Then we will access members of tuple and print employee information.

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 pass a tuple as a parameter is given below. The given program is compiled and executed successfully.

// Rust program to pass a tuple 
// as a parameter

fn PrintEmployee(emp:(i32,&str,u8))
{
   println!("Employee Information: ");
   println!("\tEmployee Id  : {}",emp.0);
   println!("\tEmployee Name: {}",emp.1);
   println!("\tEmployee Age : {}",emp.2); 
}

fn main() {
   let MyTuple:(i32,&str,u8) = (101,"Dhairya Pratap",25);
   PrintEmployee(MyTuple);
}

Output:

Employee Information: 
        Employee Id  : 101
        Employee Name: Dhairya Pratap
        Employee Age : 25

Explanation:

In the above program, we created two functions PrintEmployee() and main(). The PrintEmployee() function accept tuple as a parameter and prints employee information on the console screen.

In the main() function, we created a tuple MyTuple that contains employee information. Then we called PrintEmployee() function and printed the result.

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

total answers (1)

Rust program to implement destructive assignment w... >>
<< Rust program to access members of tuple one by one...