Junior — Middle
What amount of memory is allocated for a class instance with zero properties?
sobes.tech AI
Answer from AI
The C++ standard does not specify the exact size of an instance of a class with zero properties, but compilers typically allocate at least 1 byte of memory for each class object. This is necessary so that each object has a unique address in memory.
Example:
class Empty {};
int main() {
Empty e;
std::cout << sizeof(e) << std::endl; // Usually outputs 1
}
Thus, even if a class contains no data, its instance occupies at least 1 byte.