I think object "a" has an address, right? Does it occupy some memory? If so, how many bytes it occupy?
IIRC the standard mandates that every object has an address, and the minimum size of an object (as returned by sizeof
) is 1. That being said, probably the optimizer will make that variable disappear (maybe unless you explicitly ask for its address).
Unless it is a bit-field (9.6), a most derived object shall have a non-zero size and shall occupy one or more bytes of storage. Base class subobjects may have zero size. [...]
Unless an object is a bit-field or a base class subobject of zero size, the address of that object is the address of the first byte it occupies. Two distinct objects that are neither bit-fields nor base class subobjects of zero size shall have distinct addresses.4
Note 4: Under the “as-if” rule an implementation is allowed to store two objects at the same machine address or not store an
object at all if the program cannot observe the difference (1.9).
(C++11 §1.8 ¶5-6)
What happens if object "a" with a type void.
void
can't be used to declare variables, since it's an "incomplete type".
The void
type has an empty set of values. The void
type is an incomplete type that cannot be completed.
(C++11 §3.9.1 ¶9)