( ).
Struct student
{
char name[30];
Int kurs;
char group[3];
Int index;
} stud1, stud2;
(dot).
strcpy(stud.name, ..); printf(%s,stud2.group);
, , . :
struct student stud1kurs[200];
200 student stud1kurs[0], stud1kurs[1] . .
kurs 25- stud1kurs[24].kurs
, stud1=stud2; . , , .
, . .
:
func1(first.a); func2(&second.b);
:
#include <stdio.h>
/* */
Struct stru
{
Int x;
Char y;
};
void f(struct stru param); /* */
Main(void)
{
Struct stru arg;
arg.x=1; arg.y=2;
F(arg);
Return 0;
}
Void f(struct stru param)
{
printf(%d %d \n,param.x, param.y);
}
. : trsuct stru *adr_pointer;
adr_pointer struct stru.
, . . . , .
Struct complex
{
Float x;
Float y;
} c1, c2;
struct complex *a; /* */
a=&c1; /* 1 */
x c1 : (*a).x;
. , , (*a).x, -> (, arrow).
(*a).x a -> x.
|
|
, .
:
Struct addr
{
char city[30],street[30];
Int house;
};
Struct fulladdr
{
Struct addr address;
Int room;
char name[30];
} f,g;
f.address.house=101; /* house address f */
.
, , - (bit-fields). , , . :
Struct _
{
1:__;
2:__;
.
N:__;
};
: {int, unsigned, signed}
I , (). 8. , :
Struct onebit
{
unsigned one_bit: 1;
} obj;
obj 8 , .
.
. . , , :
Union u
{
Int i;
Char ch;
Long int l;
};
. . :
Union u alfa, beta;
. union , , . alfa 4 . . , : u.ch=5;
->, .
, , ASCII , :
#include <stdio.h>
#include <conio.h>
/* */
struct byte {
int b1: 1;
int b2: 1;
int b3: 1;
int b4: 1;
int b5: 1;
int b6: 1;
int b7: 1;
int b8: 1;
}; /* */
union bits {
Char ch;
Struct byte b;
} u; /* */
void decode(union bits u); /* */
Main(void)
{
do {
u.ch=getche();
printf(: );
Decode(u);
} while(u.ch!=q);
Return 0;
}
Void decode(union bits u)
{
if (u.b.b8) printf(1);
else printf(0);
if (u.b.b7) printf(1);
else printf(0);
if (u.b.b6) printf(1);
else printf(0);
if (u.b.b5) printf(1);
else printf(0);
if (u.b.b4) printf(1);
else printf(0);
if (u.b.b3) printf(1);
else printf(0);
if (u.b.b2) printf(1);
else printf(0);
if (u.b.b1) printf(1);
else printf(0);
printf(\n);
}
|
|
(enumeration) . , . : num _{_} ;
. : enum seasons {win, spr, sum, aut }; enum seasons s;
, win, spr, sum, aut . , 0, 1, 2. 3. , :
enum value {one=1, two, three, ten=10,thousand=1000,next);
printf(%d %d %d %d %d\n,one, two, ten, thousand, next);
1 2 10 1000 1001
:
- enum ;
- ;
- enum (i=win aut).
typedef
. typedef. . :