Rust: Day 3, Arithmatic

2026-11-13来源 dev.toEnglish

Hello there developer community. This is my second day learning rust so I decided to try something simple. How do I add 20 and 30 together. So this is me trying to figure that out. I encounted some issues with the "Unique" variable types, Like what the hell is i32. But anyway. This is my first attempt.

fn main() { let a i32: 20; let b i32: 30; println!("{}", a + b); } 

This is an example of apparently the wrong thing. Because to assign types you need to use let a: i32 = 20; but I didn't know this by the time I was learning this. The correct method of doing this is below.

fn main() { let a: i32 = 20; let b: i32 = 30; println!("{}", a + b); } 

And this program outputs:

50 

Next post I am going to attempt conditional logic and function calling so well yeah, stay tuned. And lastly, I hope my suffering brings comfort to those who as well are learning rust that I may help you in your journey.

原文:https://www.a8q9.cn/en/article/rust-day-3-arithmatic-cf0f8c.html

相关文章