C++ Deck 8 Flashcards
What is a c-string?
A char array that ends with the null character ‘\0’
What is null termination?
Since array size needs to be known at compile time, the null character \0 is inserted at the end of a c-string array to let the compiler know that the string has ended (even if all allocated spaces in the array are not currently used.)
What are three things that a c-string can do that a typical integer array cannot?
- Directly initialize with a quoted literal.
- Directly print with cout (no loop required)
- Directly read one “word” with cin (again, no loop required)
Can a c-string store character literals in single quotes such as ‘a’, ‘\n’, and ‘$’?
Yes.
What does the function:
int toupper(int c)
do?
Returns the uppercase version of c if it’s a lowercase letter, otherwise returns c as-is
What does the function:
int tolower(int c)
do?
Returns the lowercase version of c if it’s an uppercase letter, otherwise returns c as-is.
What does the function:
int isdigit(int c)
do?
Determines whether the parameter is a digit (0-9) and returns true or false based on the result.
What does the function:
int isalpha(int c)
do?
Determines whether the character is a letter (a-z, A-Z) and returns true or false depending on the result.
What does the function:
int isdigit(int c)
do?
Determines whether or not c is a letter OR a number and returns true or false based on the result.
What does the function:
int islower(int c)
do?
Determines whether or not the character is lowercase and returns true or false based on the result.
What does the function:
int isupper(int c)
do?
Determines whether or not c is uppercase and returns true or false based on the result.
What does the function:
int isxdigit(int c)
do?
Determines whether or not a c is a hex character (0-9, a-f) and returns true or false as a result.
What does the function:
int isspace(int c)
do?
Determines whether or not c is a whitespace character and returns true or false based on the result.
What does the function:
int iscntrl(int c)
do?
Determines whether or not c is a control character (e.g. ‘\n’) and returns true or false based on the result.
What does the function:
int ispunct(int c)
do?
Determines whether or not c is a printable character (other than a space, letter, or digit) and returns true or false based on the result.