wpe41.gif (23084 bytes)CIS3355: Business Data Structures
Fall, 2008
 

What happens if we forgot to add a NULL Character to a string?????

    Before we can answer this question we need to know what is a null character.

     It is a special character at the end of an array.  It requires 1 additional byte of storage.  The null character is used in replace

      of having to count the characters (including spacing and punctuation) in an array.

 

     Null Character is normally represented by:  '\0";

 

bullet

Strange things can happen. Consider the following c code:

bulletThe output of this program might appear as:

   HelloZS

 

Why  ?????????

REMEMBER:

bulletThe function puts will keep printing characters until the null character is reached.  Since the null character was not inserted, it will continue until it reaches any Null character.

 

TIPS:

    C Code 5.10.   Allows you input the program:

          char chararray[] = "Hello";

    The subscript is completely omitted.  And the C compiler will automatically determine how many bytes are needed (including the Null character).

 

Q1.  In these diagrams above, at what address should the NULL character be located if the program entered was

                    char chararray[6];

                        chararray[0] = 'H'

                        chararray[1] = 'e'

                        chararray[2] = 'l'

                        chararray[3] = 'l'

                        chararray[4] = 'o'

                        chararray[5] = '\0'

A.  1203                                 B.  1205                                  C.  1207                             D.  1200

 

Q2.  A NULL character requires how many additional bytes?

A.  two                                    B.  eight                                            C. six                               D.  one

 

Answers:  1.) B                   2.) D