1. Home
  2. Computer Science MCQs
  3. C++ and Object-Oriented Programming
  4. For int x = 0; what do decltype(x) and decltype((x)) yield?

Added 30 Nov -0001

For int x = 0; what do decltype(x) and decltype((x)) yield?

  1. int and int, because parentheses are ignored entirely by the decltype specifier
  2. int& and int&, because decltype always adds a reference to any named variable
  3. int and int&, because a parenthesised lvalue expression produces a reference type Correct answer
  4. int& and int, because the extra pair of parentheses strips the reference from the type

Correct answer

C. int and int&, because a parenthesised lvalue expression produces a reference type

12 views

MCQSEXAM

Explanation

decltype has two rules: an unparenthesised id-expression yields the declared type, while any other expression yields a reference for lvalues, so decltype((x)) is int&. The distinction matters in forwarding wrappers where the return type must preserve the value category. Combined with auto as decltype(auto), the same rules apply to deduced return types.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C++ and Object-Oriented Programming MCQs

Practise all C++ and Object-Oriented Programming MCQs

Similar MCQs