C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

Home » C++ programming language

C++ Empty class - Size, Declaration, Object Creation

Here, we will learn about C++ Empty Class, how to declare an empty class, how to create an empty class's object and what is the size of an empty class/object?

C++ allows creating an Empty class, yes! We can declare an empty class and its object. The declaration of Empty class and its object are same as normal class and object declaration.

What is the size of an Empty class's object?

An Empty class's object will take only one byte in the memory; since class doesn't have any data member it will take minimum memory storage. One byte is the minimum memory amount that could be occupied.

(Reference: Q. 4.25 Test your C++ Skills by Yashavant Kanetkar)

Let’s consider the following program

#include <iostream>
using namespace std;

class Example
int main()
	Example objEx;
	cout<<"Size of objEx is: "<<sizeof(objEx)<<endl;
	return 0;
    Size of objEx is: 1

Here Example is an empty class which does not has any data member and member function, and objEx is the object of class Example. See the output "Size of objEx is: 1".