Sams Teach Yourself C in 21 Days

(singke) #1
Working with Characters and Strings 245

10


Q What happens if I put a string into a character array that is bigger than the
array?
AThis can cause a hard-to-find error. You can do this in C, but anything stored in the
memory directly after the character array is overwritten. This could be an area of
memory not used, some other data, or some vital system information. Your results
will depend on what you overwrite. Often, nothing happens for a while. You don’t
want to do this.

Workshop ............................................................................................................


The Workshop provides quiz questions to help you solidify your understanding of the
material covered and exercises to provide you with experience in using what you’ve
learned.

Quiz ..............................................................................................................


  1. What is the range of numeric values in the ASCII character set?

  2. When the C compiler encounters a single character enclosed in single quotation
    marks, how is it interpreted?

  3. What is C’s definition of a string?

  4. What is a literal string?

  5. To store a string of ncharacters, you need a character array of n+1elements. Why
    is the extra element needed?

  6. When the C compiler encounters a literal string, how is it interpreted?

  7. Using the ASCII chart in Appendix A, state the numeric value stored for each of
    the following:
    a. a
    b. A
    c. 9
    d. a space
    e.Œ
    f.F


17 448201x-CH10 8/13/02 11:17 AM Page 245

Free download pdf