Q:

Rust program to create constants

belongs to collection: Rust Basic Programs

0

Here, we will create constants using the const keyword and print them on the screen.

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 create constants is given below. The given program is compiled and executed successfully.

// Rust program to create constants

fn main() {
    const const1:i32=10;        //32-bit signed integer 
    const const2:f32=30.12;     //32-bit floating point number
    const const3:bool=true;     //Boolean value
    const const4:char='A';      //Character
    
    println!("Constant1: {}",const1);
    println!("Constant2: {}",const2);
    println!("Constant3: {}",const3);
    println!("Constant4: {}",const4);
}

Output:

onstant1: 10
Constant2: 30.12
Constant3: true
Constant4: A

Explanation:

Here, we created 4 constants using the const keyword. Then we printed the value of constants using println!() macro.

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

total answers (1)

Rust Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Rust program to demonstrate the isize and usize da... >>
<< Rust program to create mutable variables...