The size of a class object is the same as the size of a structure object in C. i.e., the sum of sizes of all its data members.

However, if an object has no data members its size would be one byte rather than zero bytes because the minimum amount of memory that can be allocated for a variable is one byte.

Size of Object in C++ program

#include<iostream>
using namespace std;
class SizeOfObject{ 
int t,p,s;
public: void input(){ 
cout<<"Enter two Numbers"<<endl;
cin>>t>>p; } 
void print(){ 
s=t+p;
cout<<"The sum of two number is"<<s<<endl;
} }; 
int main(){ 
SizeOfObject ob1; ob1.input();
ob1.print(); 
cout<<"The Size of ob1 Object is "<<sizeof(ob1)<<" bytes"; 
return 0; }

Output:-Enter two Numbers 8 8
The sum of two number is16
The Size of ob1 Object is 12 bytes

This article is written by our awesome writer
Comments to: How to Find Size of an Object In C++

Your email address will not be published. Required fields are marked *

Attach images - Only PNG, JPG, JPEG and GIF are supported.

New Dark Mode Is Here

Sign In to access the new Dark Mode reading option.

Join our Newsletter

Get our monthly recap with the latest news, articles and resources.

By subscribing you agree to our Privacy Policy.

Latest Articles

Explore Tutorials By Categories

About

Codeverb is simply an all in one interactive learning portal, we regularly add new topics and keep improving the existing ones, if you have any suggestions, questions, bugs issue or any other queries you can simply reach us via the contact page

Login

Welcome to Codeverb

Ready to learn something new?
Join Codeverb!

Read Smart, Save Time
  •  
    Strength indicator
  •  
  •  
    Log In | Lost Password