rustConst pointer example in Rust
A const pointer in Rust is a pointer that points to a value that cannot be changed. An example of a const pointer in Rust is shown below:
let x = 5;
let y = &x;
let z: &const i32 = y;
In this example, x is an i32 variable with the value 5. y is a pointer to x, and z is a const pointer to y.
Output example
No output is produced from this code.
Explanation
The let x = 5; statement creates an i32 variable x with the value 5. The let y = &x; statement creates a pointer y to x. The let z: &const i32 = y; statement creates a const pointer z to y.
Relevant links
Related
- Example of pointer offset in Rust
- Creating pointer from specific address in Rust
- How to get pointer of struct in Rust
- Weak pointer example in Rust
- How to get address of pointer in Rust
- How to get size of pointer in Rust
- How to cast pointer to usize in Rust
- How to get pointer of object in Rust
- Pointer to array element in Rust
- How to get next pointer in Rust
More of Rust
- Regex example to match multiline string in Rust?
- How to map a Rust slice?
- How to replace a capture group using Rust regex?
- How to use regex captures in Rust?
- How to create a HashMap of structs in Rust?
- How to use non-capturing groups in Rust regex?
- How to match the end of a line in a Rust regex?
- How to use regex with bytes in Rust?
- How to perform matrix operations in Rust?
- How to use regex lookbehind in Rust?
See more codes...