Rust की मूल बातें
Hello World in Rust: Structure of a Program
Write your first Rust program and see what each part does: fn main, the braces and println!.
आप क्या सीखेंगे
- Where a Rust program starts
- Printing with println!
- Why println! ends with !
From source to output
- 1
main.rsYou write the code - 2
rustcThe compiler checks and builds it - 3
main()The program starts in main - 4
Hello, Rust!The text appears
How a Rust program runs
Every Rust program starts in a function called main. The println! macro prints a line of text; the exclamation mark shows that it is a macro, not an ordinary function.
fn declares a function and the braces hold its body. Each statement ends with a semicolon. The compiler turns the file into a program, then the program runs main and prints the text.
मुख्य बातें
- Every program starts in fn main.
- println! is a macro: the ! tells you so.
- rustc compiles the file into a program before it runs.
चलने योग्य Rust उदाहरण
Rust
main.rs
fn main() {
println!("Hello, Rust!");
}
Hello, Rust!अभ्यास
उदाहरण को ऑनलाइन कंपाइलर में खोलें, कोई मान बदलें या एक पंक्ति जोड़ें, और चलाने से पहले आउटपुट का अनुमान लगाएँ। फिर कोड में जान-बूझकर गलती करें और कंपाइलर का संदेश पढ़ें।
यह पाठ पूरा कर लिया?
अपनी प्रगति ट्रैक करने के लिए इसे सीखा हुआ मार्क करें।
आपकी प्रगति इस ब्राउज़र में सेव है इसे हर डिवाइस पर रखने के लिए साइन इन करें।
चैलेंज से अभ्यास करें
इस पाठ में सीखी बात से एक असली समस्या हल करें। हर चैलेंज ब्राउज़र में चलता है, तुरंत टेस्ट और AI रिव्यू के साथ।
- विषम, सम या कोई नहीं किसी संख्या को वर्गीकृत करें कि वह विषम पूर्णांक है, सम पूर्णांक है, या इनमें से कोई नहीं। आसान
- संख्या का वर्ग किसी पूर्णांक को स्वयं से गुणा करें। आसान