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
- How to cast pointer to usize 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 size of pointer in Rust
- How to get pointer to variable in Rust
- How to do pointer write in Rust
- How to convert pointer to reference in Rust
- How to iterate over pointer in Rust
More of Rust
- Generator example in Rust
- How to replace a capture group using Rust regex?
- How to match a URL with a regex in Rust?
- How to use binary regex in Rust?
- How to use regex lookahead in Rust?
- How to make regex case insensitive in Rust?
- Regex example to match multiline string in Rust?
- How to use regex to match a double quote in Rust?
- Yield example in Rust
- How to use a tuple as a key in a Rust HashMap?
See more codes...