'What are the differences between a pointer and a reference in Rust?

A pointer * and a reference & in Rust share the same representation (they both represent the memory address of a piece of data).

What's the practical differences when writing code though?

When porting C++ code to Rust, can they be replaced safely (C++ pointer --> rust pointer, C++ reference --> rust reference) ?



Solution 1:[1]

Rust references are just a pointer, but the compiler endows them with borrowing semantics. When you take an immutable reference to an object, the compiler ensures that you can't modify that object until after the derived reference is gone.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 NovaDenizen