Skip to content

Incorrect solution for 5th example of ownership #565

@den319

Description

@den319

fn main() { let x = (1, 2, (), "hello"); let y = x; println!("{:?}, {:?}", x, y); }
The above code is the solution of 5th code snippet of topic named ownership.

The correct solution is here:

fn main() { let x = (1, 2, (), "hello"); let y = &x; println!("{:?}, {:?}", x, y); }

As "y=x" will take the ownership of "x" and we are using the "x" in "println!" and code panics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions