What does auto do on variable declarations, exactly? And how should we think about auto? In this GotW, we’ll start taking a look at C++’s oldest new feature.



Problem



JG Questions



1. What is the oldest C++11 feature? Explain.

2. What does auto mean when declaring a local variable?

Guru Questions



3. In the following code, what is the type of variables a through k, and why? Explain.

int val = 0;

auto a = val;

auto& b = val;

const auto c = val;

const auto& d = val;



int& ir = val;

auto e = ir;



int* ip = &val;

auto f = ip;



const int ci = val;

auto g = ci;



const int& cir = val;

auto h = cir;



const int* cip = &val;

auto i = cip;



int* const ipc = &val;

auto j = ipc;



const int* const cipc = &val;

auto k = cipc;

4. In the following code, what type does auto deduce for variables a and b, and why? Explain.