CSCI 240 - Quiz Questions - Week 14
1. (2) strlen() returns
a) the number of chars in an array of char, including the null
b) the number of chars in an array of char not including the null
c) the declared number of chars an array can hold
2. (4) Write the prototype of strchr() and describe its argument(s) and possible return values.
3. (2) What is wrong with the following (answer in words):
char s[80] = "Benjamin Franklin";
s = s + 1;
cout << s;
4. (2) Given the following:
char s[80] = "dog";
char *p = s;
Which of the following are NOT equivalent (more than one may be not
equivalent)
a. *p and *s
b. s[2] and *(p + 2)
c. *(p + 0) and s
d. s[2] and (p+2)
e. *s[2] and *p + 2
f. *p + 2 and s[2]
5. (2) What must be true of the arguments to strcat(s1, s2).
Choose the most complete answer.
a. both s1 and s2 must be valid strings
b. only s2 must be a valid string
c. both s1 and s2 must be valid strings and s1 must have room to contain the
result
d. only s2 must be a valid string and s1 must have room to contain the result
6. (2) If you add 1 to a int* variable named ptr, what is the effect on ptr? That is, describe what ptr now points to.
7. (4) Write a complete function to find and return the length of a string using subscript notation. Like: str[i]
8. (4) Write a complete function to find and return the length of a string using pointer notation. Like: *p where p is a char * variable
9. (4) Write a complete function to find and return the length of a string using (base + integer) notation. Like: *(str + i)