Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up

What is the purpose of std::optional?

  1. A To represent a value that may or may not be present, without using a null pointer or sentinel
  2. B To make a type nullable at runtime
  3. C To optimise memory layout
  4. D To defer construction to another thread
Answer

To represent a value that may or may not be present, without using a null pointer or sentinel

optional expresses absence in the type system, which is clearer and safer than a magic value such as -1 or a nullable pointer.

All C++ MCQs

Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up as