Structures and Unions Flashcards

1
Q

what are stuctures ?

A

A mixed-type compound data type comprised of two or more data elements that can be of
different types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Creating New Types in C

A

typedef <existing> <new>;</new></existing>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Declaring Structures Types

A

struct <tag> {</tag>

<variable>
};
</variable>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

why use tydef when making a struct?

A

hate typing struct <tag> whenever they need to refer to a structure’s
type. So they use a typedef to give the structure type an alternate, shorter name.</tag>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Initializing a Structure Variable

A

After the variable definition, the values of structure members can only be updated individually

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Accessing Structure Members

A

cabbage . retail_price

<struct>.< member name >
</struct>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Comparing Structures

A

Structures cannot be directly compared for equality, even if they are of the same type.

to
determine if two structures contain exactly the same data in all of their members, the comparison has
to be done manually for each member,

if( cabbage . retail_price == fire_flakes . retail_price &&
22 cabbage . number_in_stock == fire_flakes . number_in_stock &&
23 strcmp ( cabbage . product_name , fire_flakes . product_name ) == 0 )
24 {

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Greater or less than

A

if( strcmp ( cabbage . product_name , fire_flakes . product_name ) < 0 ) {
10.6 Unions 141
printf (“ cabbage comes before fire_flakes \n”);
}
else if( strcmp ( cabbage . product_name , fire_flakes . product_name ) > 0) {
printf (“ cabbage comes after fire_flake \n”);
}
else {
printf (“The product names are the same .\n”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly