What will
a
be?
int
, since that's the type of 4
.
Will
x
be of type*B
or of type*A
?
B*
, since that's the type of new B()
.
Is there an exact list of the
auto
behaviour?
Usually, it's the type of the initialiser; unless that's a reference type, in which case it's the underlying object type. There are a few other wrinkles for unusual types like arrays, as mentioned in the comments.
will it always be the exact same type (with the exact same bit length!) on each compiler and each architecture?
In most cases, the initialiser has a well-defined type, and that determines the type deduced by auto
.
If the initialiser is an integer literal, then the type might depend on the platform; for example, 1000000
might be int
on a 32-bit platform, but long
on a 16-bit platform.