Chapter 8: Arrays and Strings (cont.)
In C++, what is the null character represented as?
*'\0'*
What is a c-string? (ws18)
- character arrays - null terminated - A character array is an array whose components are of type char.
What does *strcmp(s1, s2)* do? (ws18)
- compares *s2* to *s1* - returns 0 if they are the same - returns < 0 if s1 < s2 - returns > 0 if s1 > s2
What does *strcpy(s1, s2)* do? (ws18)
- copies the string *s2* into the string variable *s1* - length of *s1* should be at least as large as *s2* - It does not check to make sure that *s1* is as large as *s2*.
In C++, what is a string?
Any sequence of characters enclosed between double quotation marks.
What happens if the there is not enough room in *s1* to hold *s2*? (ws18)
If there is not enough room in *s1* to hold *s2*, then there will be an overflow.
What is the only place where C++ allows aggregate operations?
Input and output of c-strings
Does the function *strlen(s)* return the size of the array? (ws18)
No, an array of characters can have a larger size but the c-string itself can have a different length.
How can I find the length of a c-string? (ws18)
The function *strlen(s)* returns the length of the string *s*, excluding the null character.
What C++ library contains the c-string prototypes? (ws18)
To use the c-string prototypes, the program must include the header file *cstring* via the *include* statement.
How do you prevent functions from modifying arrays?
Using the reserved word *const* before the data type
Can individual array components be passed as parameters to functions?
Yes
How do you declare a two-dimensional array as a formal parameter?
You can omit the size of the first dimension, but not the second.
How do you pass an array as an actual parameter in a function call statement?
You use only its name.
How do you declare a one-dimensional array as a formal parameter?
You usually omit the array size.