Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

Exercises

1:Locate the system header files stdio.h, limits.h, and float.h on your machine (on Unix systems, look inside the /usr/include directory). Examine the files to see what's in them. If these files include other header files, be sure to track them down as well to examine their contents.
2:Define a macro called MIN that gives the minimum of two values. Then write a program to test the macro definition.
3:Define a macro called MAX3 that gives the maximum of three values. Write a program to test the definition.
4:Write a macro called IS_UPPER_CASE that gives a nonzero value if a character is an uppercase letter.
5:Write a macro called IS_ALPHABETIC that gives a nonzero value if a character is an alphabetic character. Have the macro use the IS_LOWER_CASE macro defined in the chapter text and the IS_UPPER_CASE macro defined in exercise 4.
6:Write a macro called IS_DIGIT that gives a nonzero value if a character is a digit '0' through '9'. Use this macro in the definition of another macro called IS_SPECIAL, which gives a nonzero result if a character is a special character—that is, not alphabetic and not a digit. Be sure to use the IS_ALPHABETIC macro developed in exercise 5.
7:Write a macro called ABSOLUTE_VALUE that computes the absolute value of its argument. Make sure that an expression such as
90

ABSOLUTE_VALUE (x + delta)

is properly evaluated by the macro.

8:Consider the definition of the printint macro from this chapter:
90

#define printx(n)  printf ("%i\n", x ## n)

Could the following be used to display the values of the 100 variables x1x100? Why or why not?

90

for ( i = 1; i <= 100; ++i )
  printx (i);


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial