C

[The C Programming Language] Chanpter 6. Structures

구씨언니 2021. 3. 6. 19:48
반응형

6.1 Basics of Structures 중 발췌

 

A struct decalration defines a type. The right brace that terminates the list of members may be followed variables, just as for any basic type. That is,

struct { ... } x, y, z;

is syntactically analogous to

int x, y, z;

In the sense that each statement declares x, y and z to be variavles of the named type and causes to be set aside for them.

 

A member of a particular structure is referred to in an expression by a construction of the form

structure-name.member

the structure member operator "." Connects the structure name and the member name.

//To print the coordinates of the point pt,
printf("%d,%d", pt.x, pt.y);

//or to compute the distance from the origin (0, 0) to pt
double dist, sqrt(double);

dist = sqrt((double)pt.x*pt.x + (double)pt.y*pt.y);

 

반응형