Rust program to demonstrate the assignment operators

Here, we are going to demonstrate the assignment operators in Rust programming language.
Submitted by Nidhi, on September 22, 2021

Problem Solution:

Here, we will create three integer variables and perform assignment operations, and print results.

Program/Source Code:

The source code to demonstrate the assignment operators is given below. The given program is compiled and executed successfully.

// Rust program to demonstrate the 
// assignment operators

fn main() {
    let mut num1:i32=27;
    let mut num2:i32=5;
    let mut num3:i32=0;
    
    num3 = num1+num2;
    println!("Result(=) :{}",num3);

    num3 += num1;
    println!("Result(+=) :{}",num3);

    num3 -= num1;
    println!("Result(-=) :{}",num3);

    num3 *= num1;
    println!("Result(*=) :{}",num3);

    num3 /= num1;
    println!("Result(/=) :{}",num3);
}

Output:

Result(=) :32
Result(+=) :59
Result(-=) :32
Result(*=) :864
Result(/=) :32

Explanation:

Here, we created three integer variables num1, num2, and num3 that are initialized with 27, 5, 0 respectively. Then we performed assignment operations and printed the result.

Rust Basic Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.