struct (keyword)
Groups variables into a single record
Syntax:
struct [<struct type name>] {
[<type> <variable-name[, variable-name, ...]>] ;
[<type> <variable-name[, variable-name, ...]>] ;
...
} [<structure variables>] ;
A struct, like a union, groups variables into a single record.
Though both <struct type name> and <structure variables> are optional, one
of the two must appear.
Elements in the record are defined by naming a <type>, followed by one or
more <variable-name> (separated by commas).
Different variable types can be separated by a semicolon.
Example:
struct my_struct {
char name[80], phone_number[80];
int age, height;
} my_friend;
This struct declares an array of records containing two strings (name and
phone_number) and two integers (age and height).
To access elements in a structure, you use a record selector (.). For
example,
strcpy(my_friend.name,"Mr. Wizard");
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment