Skip to content

Commit a6bb340

Browse files
authored
More detail about expression and statement
1 parent d33de0c commit a6bb340

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

functions/functions5.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,8 @@ fn square(num: i32) -> i32 {
4040

4141
// This is a really common error that can be fixed by removing one character.
4242
// It happens because Rust distinguishes between expressions and statements: expressions return
43-
// a value and statements don't. We want to return a value from the `square` function, but it
44-
// isn't returning one right now...
43+
// a value based on its operand and statements simply retun a `()` type which just like `void` in C/C++ language.
44+
// We want to return a value of `i32` type from the `square` function, but it is returning a `()` type...
45+
// They are not the same. There are two solusions:
46+
// 1. Add a `return` ahead of `num * num;`
47+
// 2. remove `;`, make it to be `num * num`

0 commit comments

Comments
 (0)