Chap8 10
Chap8 10
• Structures—sometimes referred to as
aggregates—are collections of related variables
under one name.
• Structures may contain variables of many
different data types—
– in contrast to arrays, which contain only
elements of the same data type.
• Structures are commonly used to define records
to be stored in files (see Chapter 11, C File
Processing).
© 2016 Pearson Education, Ltd. All rights reserved.
10.1 Introduction (Cont.)
• We’ll also discuss:
– typedefs—for creating aliases for previously defined
data types
– unions—derived data types like structures, but with
members that share the same storage space
– bitwise operators—for manipulating the bits of
integral operands
– bit fields—unsigned int or int members of structures
or unions for which you specify the number of bits in
which the members are stored, helping you pack
information tightly
– enumerations—sets of integer constants represented
by identifiers.
10.2 Structure Definitions
• The bitwise exclusive OR operator (^) sets each bit in the result
to 1 if exactly one of the corresponding bits in its two
operands is 1.
• In Fig. 10.9, variables number1 and number2 are assigned the
values 139 (00000000 00000000 00000000 10001011) and
199 (00000000 00000000 00000000 11000111)
• When these variables are combined with the bitwise exclusive
OR operator in the expression number1 ^ number2, the result
is 00000000 00000000 00000000 01001100.
• Figure 10.12 summarizes the results of combining two bits
with the bitwise exclusive OR operator.
10.9.3 Using the Bitwise AND, Inclusive OR, Exclusive OR and
Complement Operators (Cont.)