Rust program to create constants

Here, we are going to learn how to create constants in Rust programming language?
Submitted by Nidhi, on September 21, 2021

Problem Solution:

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

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);


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


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

Rust Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻

Copyright © 2024 All rights reserved.