🔹 decltype —

Type Deduction Keyword

🧠 What is it?

decltype inspects the type of an expression without evaluating it and gives you its exact type at compile-time.

It’s useful when you want to:


✅ Basic Syntax

int x = 5;
decltype(x) y = 10;  // y is of type int

You’re saying: “Let the type of y be the same as the type of x.”


🧪 Examples

1. Basic variables

double pi = 3.14;
decltype(pi) radius = 2.0;  // radius is double

2. Expressions

int a = 2;
float b = 3.5;
decltype(a + b) result;  // result is float (due to usual arithmetic conversion)

3. Functions