& (Struct a *) 10)-> I) Address offset = offsetof

Source: Internet
Author: User

# Include <stdio. h>
# Include <afx. h>
Struct {
Int I; char J; char J1;
Short int Si;
Char * PTR;
Long array [100]; char B [5]; char C1; char * C ;};

 

# Define print_me (char *) & (struct a *) 0)-> C)
Void main ()
{/*
Printf ("% d \ n", (char *) & (struct a *) 0)-> I ));
Printf ("% d \ n", (char *) & (struct a *) 0)-> j ));
Printf ("% d \ n", (char *) & (struct a *) 0)-> PTR ));
Printf ("% d \ n", (char *) & (struct a *) 0)-> array ));
Printf ("% d \ n", (char *) & (struct a *) 0)-> B ));
Printf ("% d \ n", (char *) & (struct a *) 0)-> C ));
*/
Printf ("% d \ n", & (struct a *) 10)-> I ));
Printf ("% d \ n", & (struct a *) 10)-> j ));
Printf ("% d \ n", & (struct a *) 10)-> J1 ));
Printf ("% d \ n", & (struct a *) 10)-> Si ));
Printf ("% d \ n", & (struct a *) 10)-> PTR ));
Printf ("% d \ n", & (struct a *) 10)-> array ));
Printf ("% d \ n", & (struct a *) 10)-> B ));
Printf ("% d \ n", & (struct a *) 10)-> C1 ));
Printf ("% d \ n", & (struct a *) 10)-> C ));

Printf ("% d \ n", sizeof (short INT ));
Printf ("% d \ n", sizeof (INT ));
Printf ("% d \ n", sizeof (char ));
Printf ("% d \ n", sizeof (char *));
Printf ("% d \ n", sizeof (long ));
Printf ("% d \ n", sizeof (tchar ));
// Printf ("% d \ n", print_me );
}

 

Allocate a space greater than or equal to 4 bytes, starting from an integer multiple of 4.

Allocate a space smaller than 4 bytes. If the space allocated by the first 4 integers can be put down, it is allocated to the remaining space. Otherwise, it is allocated by an integer multiple of the four.

 

& (Struct a *) 10)-> I) // considers the starting position of the struct space as 10 and returns the position of the I variable.

& (Struct a *) 0)-> I) // considers the starting position of the struct space as 0 and returns the position of the I variable.

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.