ADVERTISEMENT
ADVERTISEMENT

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

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.

Rust Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.