Explanation required.
1. It is legal to write char message[] ="Go Home!";
2. A C-string variable is an array, so it can be indexed to access individual character positions
3. A C-string is a sequence of characters terminated by the null character.
4. It is legal to assign C-string variables.
5. The C-string library functions use the null terminator to decide when to stop processing.
1. Which of the following defines the C-string containing "Hello"?
a) char stringVar[10] = "Hello";
b) char stringVar[10] = {‘H’, ‘e’, ‘l’, ‘l’, ‘o’};
c) char stringVar[10] = {‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ‘\0’};
d) char stringVar[6] = "Hello";
e) char stringVar[] = "Hello";
2. Which of the following are C-string constants? Give the number of characters in each of these.
a) ‘\n’
b) ‘n’
c) "Lamb\n"
d) "Mary"
e) "M"
3. The header file that you must #include to have access to the C++ Standard Library string class is
a) C-string
b) string.h
c) string
d) String.h
e) None of the above
1. Write a line of code that declares and initializes a C-string variable, yourString, that can hold up to 10 characters. Use the initialization string "Whoops".
2. Write code to define a C-string aString variable, of size 10 but do not initialize it. Use a library C-string library function to copy the C-string literal, "Hello" into aString.
3. Write an if-else statement using a C-string function that reports whether two C-strings variables contain the same C-string.
4. What is the longest C-string that can be put into this C-string variable? Explain.
char s[9];
5. Discuss the similarities and difference between the two declaration/initializations:
a) char s1[] = "abc";
b) char s2[] = {‘a’, ‘b’, ‘c’};