, . .
:
struct {
long L;
int i1, i2;
char c[4];
} STR1;
, :
f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff
long L int i1 int i2 char c[4]
STR1 , . - , .
, ; .
#pragma pack(push,n); n n (n=(1,2,4,8,16)). : #pragma pack(pop). #pragma pack(show) warning , : value of pragma pack(show) == 8.
, :
( ) ;
, char, ;
.
STR2 :
struct {
long L;
char c[3];
int i1, i2;
} STR2;
f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff
long L char c[3] int i1 int i2
(4+3+4+4=15) , (16) - , char c[3]; int i1 .
sizeof.
. :
|
|
struct Book { char name[20]; //
char title[44];
int year;
float price;
};
Book //
first_book =
{ Mitchel M.,
Unesennie vetrom,
2007,
20000 },
child_book =
{ Troepolskij G.,
Belij Bim Chernoe Ucho,
2006,
10000},
dog_book =
{ .. };
. .
, , . .
, , . , . :
struct UDC { char class, subclass; int number; };
struct Book { struct UDK udc_class;
char name [20];
chat title[44];
int year;
float price;
} first_book, child_book, dog_book;
, . . :
first_book.udc_class.class = A; // ( first_book. udc_class ). class.
dog_book.udc_class.number =681;
.
, , .
:
struct Book { Book my_s; // !!!!!
char name[20];
char title[44];
int year;
float price;
};
struct Book { Book* my_s; //OK!!!!!
char name[20];
char title[44];
int year;
float price;
};
:
struct Distance //
{ int km, m;
};
struct Pole //
{ Distance length;
Distance width,
};
Pole :
Pole pole = { { 2, 20 }, { 1, 5 }};