. , , . C++ .
(typedef)
, typedef:
typedef _ [ ];
. .
:
typedef unsigned int UINT;
typedef char Msg[100];
, :
UINT i, j; // unsigned int
Msg str[10]; // 10 100
, typedef : - typedef, .
(enum)
, . , .
: enum [ _ ] { _ };
, . , .
. , , :
enum Err {ERR_READ, ERR_WRITE, ERR_CONVERT};
Err error;
switch (error) {
case ERR_READ: /* */ break;
case ERR_WRITE: /* */ break;
case ERR_CONVERT: /* */ break;
}
ERR_READ, ERR_WRITE, ERR_CONVERT 0, 1 2 .
:
enum {two = 2, three, four, ten = 10, eleven, fifty = ten + 40};
three four 3 4, eleven 11.
, .
#define , ; , .
. , , .
(struct)
, , .
C++ , , :
|
|
struct [ _ ] {
_1 _1;
_2 _2;
_n _n;
} [ _ ];
, , .
, , . :
// :
struct {
char fio[30];
int date, code;
double salary;
} staff[100], *ps;
, , , :
struct Worker{ // Worker
char fio[30];
int date, code;
double salary;
}; //
// Worker Worker:
Worker staff[100], *ps;
, . . :
struct List;. // List
struct Link{
List *p; // List
Link *prev, *succ; // Link
}
struct List { /* List */};
:
struct{
char fio[30];
int date, code;
double salary;
} worker = {"", 31, 215, 3400.55};
(, ):
struct complex{
float real, im;
} compl [2][3] = {
{{1, 1}, {1, 1}, {1, 1}}, // 1, .. compl[0]
{{2, 2}, {2, 2}, {2, 2}} // 2, .. compl[1]
}
, . . .
, .
. () -> , :
Worker worker, staff[100], *ps;
worker.fio = "";
staff[8].code = 215;
ps->salary = 0.12;
, :
struct A {int a; double x;};
struct {A a; double x;} [2];
[0].. = 1;
[1]. = 0.1;
, , . , (, ) , struct.
. , , /. 1 , .
|
|
( ):
struct Options{
bool centerX:l;
bool centerY:l;
unsigned int shadow:2;
unsigned int palette:4;
}
. , . . , , .
, , , , . .
(union)
, . , , struct union.
. , .
, , :
#include <iostream.h>
int main() {
enum paytype {CARD, CHECK};
paytype ptype;
union payment{
char card[25];
long check;
} info;
/* info ptype */
switch (ptype){
case CARD: cout << " : " << info.card; break;
case CHECK: cout << " : " << info.check, break;
}
return 0;
}
, , , . , :
#include <iostream.h>
int main() {
enum paytype {CARD, CHECK};
struct{
paytype ptype;
union{
char card[25];
long check;
}
} info;
... /* info */
switch (info.ptype){
case CARD: cout << " : " << info.card; break;
case CHECK: cout << " : " << info.check; break;
}
return 0;
}
. . , :
struct Options{
bool centerX:l;
bool centerY:l;
unsigned int shadow:2;
unsigned int palette:4;
}
union{
unsigned char ch;
Options bit;
} option = {0xC4};
cout << option.bit.palette;
option.ch &= 0xF0; //
:
;
;
, , ;
.
1.22