Skip to main content

Move Semantics and Rvalue References

1).What is move semantics in C++?

1) Transferring ownership of resources without copying
2) Moving data between containers
3) Copying resources from one object to another
4) None of the above

2).Which of the following is used to enable move semantics?

1) Rvalue references
2) Copy constructor
3) Assignment operator
4) None of the above

3).What is an rvalue reference in C++?

1) A reference to a temporary object
2) A reference to a constant object
3) A reference to a global object
4) None of the above

4).What does the 'std::move()' function do?

1) It casts an lvalue to an rvalue reference
2) It moves the data from one object to another
3) It creates a copy of the object
4) None of the above

5).What is the benefit of move semantics?

1) Avoids expensive deep copies
2) Increases memory usage
3) Slows down the program
4) None of the above

6).Can an rvalue reference bind to an lvalue?

1) No
2) Yes
3) Only for constants
4) None of the above

7).What is the role of move constructor?

1) Transfers ownership of resources from one object to another
2) Copies resources from one object to another
3) Deletes resources
4) None of the above

8).Can a class have both a move constructor and a copy constructor?

1) Yes
2) No
3) Only one can exist
4) None of the above

9).What is an example of a case where move semantics should be used?

1) Returning a large object from a function
2) Passing an object to a function by reference
3) Passing an object to a function by value
4) None of the above

10).What happens if a move constructor is not defined?

1) The compiler will use the copy constructor instead
2) The program will throw an error
3) The program will crash
4) None of the above