Ask Your Question

Why has i been declared as &usize instead of usize in Rustlings Quiz2?

asked 2023-05-21 05:55:43 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2023-05-21 06:22:02 +0000

qstack gravatar image

It is because the variable i is being used as a reference, meaning it will hold a memory address instead of the actual value. Therefore, it needs to be declared as a reference to a usize type, which is denoted by &usize. This is a common practice in Rust to ensure safe memory management and avoid issues such as null pointer dereferencing.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer

Question Tools


Asked: 2023-05-21 05:55:43 +0000

Seen: 22 times

Last updated: May 21 '23