Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::ptr;
- struct A {
- a: i32,
- b: *const i32
- }
- impl A {
- pub fn new(a: i32) -> Self {
- let mut result = Self {
- a,
- b: ptr::null()
- };
- let ptr = &result.a as *const _;
- result.b = ptr;
- unsafe {
- println!("{}", *result.b);
- }
- result
- }
- }
- fn main() {
- let a = A::new(10);
- unsafe {
- println!("{}", *a.b);
- }
- }
Add Comment
Please, Sign In to add comment