Explain the 'Rule of Three', 'Rule of Five', and 'Rule of Zero'.

Last updated 21 June 2026

  • Rule of Three: if a class defines its destructor, copy constructor, or copy assignment, it needs all three. Missing one causes leaks, double-frees, or shallow copies.

  • Rule of Five (C++11) adds move constructor and move assignment. Declaring a destructor or copy op suppresses implicit moves, so define them explicitly (= default / = delete help).

  • Rule of Zero: preferably define none by holding resources in RAII members (std::unique_ptr, std::vector, std::string) so compiler-generated specials are correct.

  • https://utkrusht.ai/blog/cplusplus-interview-questions
  • https://roadmap.sh/questions/cpp
  • https://internshala.com/blog/cpp-coding-interview-questions/
All C++ interview questions