on-internet
← Community

Does reassignment with the same variable name in Rust not allow for reclamation of the originally assigned variable?

Stack Overflow ·

Take the following snippet as an example (from the Rust bible): let x = 5; //A let x = x+1; //B My understanding is as follows: The program implicitly defines x as a u32 integer (or some other int type) with a value of 5 (A). It defaults to an immutable type, which means it can only be 'modified' (even though no modification of the original memory is being done) by using the let keyword. The program then reserves new memory for whatever type was implicitly defined in the prior step and binds it to the value 6. Since the new x is not bound yet/not in scope, the 'x' used during the assignment is

Comments

Sign in or sign up to comment and upvote.

No comments yet.