Which type does keyword auto default to?
c++, c++11
Solution
It doesn't "default" to anything. `65535` is an `int`, by definition, so `auto` is `int` in this case. For example, if you did `65535L`, then it's a `long`, and `auto` would be a `long`.
Note that the above is considering a "typical" system. If `65535` is too large for `int` (perhaps maybe because `int` is 16-bits on this other system), the compiler will give it a larger type so that `65535` it "fits" into its own data type, (in this case, `long`), in which case `auto` becomes `long`. The exact rules regarding the type of an integer literal are given in section 2.14.2 of the standard (thanks Benjamin Lindley and James Kanze). The important part to remember, though, is that there are specific, clear rules as to what the type of something is, so `auto` never has to guess or "default" to anything.
Problem
Currently trying to get my head round C++11 and have just discovered the auto keyword. I was wondering with the use of auto which type would it default to given certain values. For instance with an integer value of say 65535, would that default to an unsigned int, signed int, unsigned short etc? Or does it just remain as auto and not need to default to anything? Any help is appreciated