Simple instance description Class, Class Object size

Source: Internet
Author: User

The class size is the same as the class object size.

The following examples are described:

Class firstclass // define a class

{
Public:
Firstclass ()
{}

PRIVATE:
Int I; // 4
Float F; // 4
Char C; // 1, to be aligned, and finally 4
};

Int main ()
{
Int I = sizeof (firstclass); // evaluate the class size, which is 12
Cout <I <"" <sizeof (float) <Endl;
Firstclass FC; // defines a Class Object
Int J = sizeof (FC); // the size of the class object, which is 12
Cout <j <Endl;

If (I = J)

{
Cout <"equal \ n"; // execute this row
}
Else
{
Cout <"different \ n ";
}

Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.