【正文】
sequence, and an optional enumerated list name can be used – enum escsequences {BELL = 39。\a39。,BACKSPACE = 39。\b39。,NEWLINE = 39。\n39。, RETURN = 39。\r39。, TAB =39。\t39。}。 ? Enumerated constants can be any valid usercreated identifier, but each name must be unique ? OK for two constants to be equated to the same integer value A First Book of ANSI C, Fourth Edition 10 Conditional Expressions ? A conditional expression uses the conditional operator, ?: and provides an alternate way of expressing a simple ifelse statement – expression1 ? expression2 : expression3 ? For example, the ifelse statement if (hours 40) rate = 。 else rate = 。 ? Can be replaced with rate = (hours 40) ? : 。 ? ?: is unique in C in that it is a ternary operator A First Book of ANSI C, Fourth Edition 11 Conditional Expressions (continued) ? Conditional expressions are only useful in replacing ifelse statements when the expressions in the equivalent ifelse statement are not long or plicated ? For example, the statement maxVal = a b ? a : b。 is a oneline statement that assigns the maximum value of the variables a and b to maxVal ? A longer, equivalent form of this statement is if (a b) maxVal = a。 else maxVal = b。 A First Book of ANSI C, Fourth Edition 12 The goto Statement ? goto provides an unconditional transfer of control to some other statement in a program – goto label。 ?label is any unique name chosen according to the rules for creating variable names ? For example, if (denom == ) goto err。 else result = num /denom。 . . err: printf(Error: Attempted Division by Zero)。 A First Book of ANSI C, Fourth Edition 13 The goto Statement (continued) ? Generally, it is much easier to call an error routine for unusual conditions or use a break statement if this is necessary, rather than use a goto ? Theoretically, a goto is never required because C’s normal structures provide sufficient flexibility to handle all possible flow control requirements ? gotos tend to plicate programs ? Using even one goto statement in a program is almost always a sign of bad programming structure A First Book of ANSI C, Fourth Edition 14 Bit Operations A First Book of ANSI C, Fourth Edition 15 The AND Operator ? amp。 causes a bitbybit AND parison between its two operands ? AND operations are extremely useful in masking, or eliminating, selected bits from an operand – For example, – The 0s in op2 effectively mask the respective bits in op1, while the ones in op2 filter the respective bits in op1 through with no change in their values – In this example, op2 is called a mask A First Book of ANSI C, Fourth Edition 16 The AND Operator (continued