Though, this question has already answered, I am posting my answer because I think the OP has doubt in structure declaration and definition of variable of a structure type.
If you don't know what is a structure in C, please have a look at 1) below.
The keyword struct introduces a structure declaration, which is a list of declarations enclosed in braces. An optional name called a structure tag may
follow the word struct. Hence, this is a structure declaration:
struct card {
char *face;
char *suit;
};
here face
and suit
are member variables. Note that a structure declaration reserves no storage; it merely describes a template of a structure.
A struct declaration defines a type. The right brace that terminates the list of members may be followed by a list of variables. So, in your case:
....
} aCard, deck[52], *cardPtr;
aCard
, deck[52]
and *cardPtr
are the variables of type struct card
.
Since your structure declaration is tagged with name card
, the tag card
can be used later in definitions of instances of the structure. e.g. given the declaration of structure card
above,
struct card someCard;
defines a variable someCard
which is a structure of type struct card
.
Alternatively, you can typedef
a structure declaration and use it to define variables of its type.
1)
By definition - A structure is a collection of one or more variables, possibly of different types, grouped together under a single name.
As per C standard#6.2.5 [Types]:
A structure type describes a sequentially allocated nonempty set of member objects (and, in certain circumstances, an incomplete array), each of which has an optionally specified name and possibly distinct type.
.....
.....
Arithmetic types and pointer types are collectively called scalar types. Array and structure types are collectively called aggregate types.46)