You've already forked comprehensive-rust
							
							
				mirror of
				https://github.com/google/comprehensive-rust.git
				synced 2025-10-31 00:27:50 +02:00 
			
		
		
		
	Clarification on references
This commit is contained in:
		| @@ -11,9 +11,18 @@ fn main() { | ||||
| } | ||||
| ``` | ||||
|  | ||||
| Some differences from C++: | ||||
| Some notes: | ||||
|  | ||||
| * We must dereference `ref_x` when assigning to it, similar to C pointers, | ||||
| * We must dereference `ref_x` when assigning to it, similar to C and C++ pointers. | ||||
| * Rust will auto-dereference in some cases, in particular when invoking | ||||
|   methods (try `count_ones`). | ||||
|   methods (try `ref_x.count_ones()`). | ||||
| * References that are declared as `mut` can be bound to different values over their lifetime. | ||||
|  | ||||
| <details> | ||||
| Key points: | ||||
|  | ||||
| * Be sure to note the difference between `let mut ref_x: &i32` and `let ref_x: | ||||
|   &mut i32`. The first one represents a mutable reference which can be bound to | ||||
|   different values, while the second represents a reference to a mutable value. | ||||
|  | ||||
| </details> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user