C / C ++ topics - structure exercises

Title: given structure

struct A
{
char t:4;
char k:4;
unsigned short i:8;
unsigned long m;
}; 

问sizeof(A) = ?


【standard answer】

8
 

topic:

struct name1{
char str;
short x;
int num;
} ;

Seek sizeof (name1)?


【standard answer】

8

topic:

struct name2{
char str;
int num;
short x;
}; 

求sizeof(name2)?


[Answer] standard 12

Title: Analyze the results of the following program is run ().

union
{
         struct
         {
         unsigned char c1:3;
         unsigned char c2:3;
         unsigned char c3:2;
         }s;
 unsigned char c;
}u;

int main()
{
         u.c=100;
         printf("%d\n",u.s.c1);
         printf("%d\n",u.s.c2);
         printf("%d\n",u.s.c3);
return 0;

}

 

【answer】

This title examines data storage format in the bit field C language. c s structure and share the same memory, the memory size of the largest member of the occupied memory size. Storing the following format:

Guess you like

Origin blog.csdn.net/chen1083376511/article/details/92002337