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
- How to get pointer to variable in Rust
- How to get pointer of struct in Rust
- Example of pointer offset in Rust
- How to cast pointer to usize in Rust
- Creating pointer from specific address in Rust
- Weak pointer example in Rust
- How to get address of pointer in Rust
- How to do pointer write in Rust
- How to create pointer in Rust
- How to get next pointer in Rust
More of Rust
- How to replace a capture group using Rust regex?
- How to match the end of a line in a Rust regex?
- How to extract data with regex in Rust?
- How to use regex with bytes in Rust?
- How to use regex to match a double quote in Rust?
- How to push an element to a Rust slice?
- How to perform matrix operations in Rust?
- How to calculate the inverse of a matrix in Rust?
- How to parse JSON string in Rust?
- How to add matrices in Rust?
See more codes...