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.
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Program/Source Code:
The source code to create constants is given below. The given program is compiled and executed successfully.
Output:
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