320 Chapter 13 The Preprocessor
Exercises
- Type in and run the three programs presented in this chapter, remembering to
type in the include file associated with Program 13.3. Compare the output pro-
duced by each program with the output presented in the text. - Locate the system header files <stdio.h>,<limits.h>,and <float.h>on your
system (on Unix systems, look inside the /usr/includedirectory). Examine the
files to see what’s in them. - Define a macro MINthat gives the minimum of two values.Then write a program
to test the macro definition. - Define a macro MAX3that gives the maximum of three values.Write a program to
test the definition. - Write a macro SHIFTto perform the identical purpose as the shiftfunction of
Program 12.3. - Write a macro IS_UPPER_CASEthat gives a nonzero value if a character is an
uppercase letter. - Write a macro IS_ALPHABETICthat gives a nonzero value if a character is an
alphabetic character. Have the macro use the IS_LOWER_CASEmacro defined in the
chapter text and the IS_UPPER_CASEmacro defined in exercise 6. - Write a macro IS_DIGITthat gives a nonzero value if a character is a digit '0'
through '9'.Use this macro in the definition of another macro IS_SPECIAL,
which gives a nonzero result if a character is a special character; that is, not alpha-
betic and not a digit. Be certain to use the IS_ALPHABETICmacro developed in
exercise 7. - Write a macro ABSOLUTE_VALUEthat computes the absolute value of its argument.
Make certain that an expression such as
ABSOLUTE_VALUE (x + delta)
is properly evaluated by the macro.
- Consider the definition of the printintmacro from this chapter:
#define printint(n) printf ("%i\n", x ## n)
Could the following be used to display the values of the 100 variables x1–x100?
Why or why not?
for (i = 1; i < 100; ++i)
printx (i);
- Test out the system library functions that are equivalent to the macros you devel-
oped in exercises 6, 7, and 8.The library functions are called isupper,isalpha,
and isdigit.You need to include the systemheader file <ctype.h>in your pro-
gram in order to use them.