CSC211

Handout #2 Strings

 

 

  1. Assume the following code:

 

      int main()

{

      char oneWord[40];

      char secondWord[20];

 

      strcpy(oneWord,"Earthquake");

      strcpy(secondWord,"Hurricane");

 

      cout << oneWord << ' ' << secondWord;

      return 0;

}

 

    1. What header files must be included for the above code to run?

 

    1. What is printed by the code if the proper header files are included?

 

    1. Can I add the following to the program?  If not, why?

 

                       i.   cout << oneWord[0];

 

                     ii.   cout << secondWord[20];

 

                    iii.   strcat(oneWord, secondWord);

 

                     iv.   cout << oneWord << secondWord;

 

  1. char line[20];

cin.getline(line,20);

 

    1. What does line contain if you type in:

 

                   i.  Hello!  How are you?

                     ii.   Peter Piper picked a peck of pickeled peppers. What did Peter Piper Pick? A peck of pickeled peppers.

                                              iii.     just the return character

 

    1. What would strlen(line) return for each of the above?