How To Use sizeof an Operator in C++

Master C++ with Real-time Projects and Kickstart Your Career Start Now!!

Program 1

// Program for Sizeof Operator
#include<iostream>
#define clrscr() system("cls")
using namespace std;
class Test1
{
    private:
    double d1;
    double d2;
    double d3;
    int n;
};
class Test2:public Test1
{
  
};

int main()
{
   clrscr();
   Test1 T1;
   Test2 T2;
   cout<<"size of class Test1 : "<<sizeof(T1);
   cout<<"\nsize of class Test2 : "<<sizeof(T2);
//    int a=34;
//    cout<<"\nsize of integer "<<sizeof(a);
//    cout<<"\nsize of double "<<sizeof(34.67);
//    cout<<"\nsize of float "<<sizeof(34.67f);
//    cout<<"\nsize of char "<<sizeof('y');
   return 0;    
}

Did we exceed your expectations?
If Yes, share your valuable feedback on Google

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

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