Automatic Type Deduction: decltype

Let's take a look at what decltype does.

We'll cover the following

decltype vs auto

The decltype keyword was also introduced in C++11, though its functionality differs from auto. decltype is used to determine the type of an expression or entity.

Here is the correct format:

decltype(expression) 

We can use auto to create variables, but decltype returns the type of an expression containing variables.

Rules

  • If the expression is an lvalue, decltype will return a reference to the data type of the expression

  • If the expression is an rvalue, decltype will return the data type of the value

Create a free account to view this lesson.

Continue your learning journey with a 14-day free trial.

By signing up, you agree to Educative's Terms of Service and Privacy Policy