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 do pointer write in Rust
- How to get size of pointer in Rust
- How to print pointer in Rust
- How to iterate over pointer in Rust
- How to print pointer value in Rust
- Null pointer in Rust
- How to increment pointer in Rust
- How to get pointer to struct in Rust
- Pointer to array element in Rust
- How to convert pointer to reference in Rust
More of Rust
- How to match a URL with a regex in Rust?
- How to use regex to match a double quote in Rust?
- How to use regex lookahead in Rust?
- How to perform matrix operations in Rust?
- How to match whitespace with a regex in Rust?
- How to replace strings using Rust regex?
- How to use non-capturing groups in Rust regex?
- Regex example to match multiline string in Rust?
- How to use regex lookbehind in Rust?
- How to replace all matches using Rust regex?
See more codes...