I am confused as to why my code can run successfully, whereas when I asked ChatGPT, it shouldn't work. I realize that variables in Rust must be declared first, but what is this? What does 'the book' mean:
Constants are valid for the entire time a program runs, within the scope in which they were declared.
fn main(){
println!("{}", TIGA_MENIT_DALAM_DETIK);
const TIGA_MENIT_DALAM_DETIK: u32 = 60 * 3;
// println!("{}", x);
// let x = 20;
}
Here is output:
CGPT suggestion:
fn main(){
// Declare the constant first
const TIGA_MENIT_DALAM_DETIK: u32 = 60 * 3;
// Now you can use it
println!("{}", TIGA_MENIT_DALAM_DETIK);
}