Chapter 8 – C How to Program 6e Multiple Choice Test Bank
Download file with the answers
Chapter 8 - C How to Program 6e Multiple Choice Test Bank
1 file(s) 295.79 KB
Not a member!
Create a FREE account here to get access and download this file with answers
8.1 Introduction
8.2 Fundamentals of Strings and Characters
8.1 Which of the following is false?
(a) A string may include letters, digits, and various special characters (i.e., +, -, * ).
(b) A string in C is an array of characters ending in the null character (‘\0’).
(c) String literals are written inside of single quotes
(d) A string may be assigned in a definition to either a character array or a variable of type char *.
8.2 A character constant is a(n) __________ value represented as a character in single quotes.
a) short
b) int
c) long
d) double
8.3 ‘\n’ represents the integer value of
a) the character n
b) the string n
c) newline
d) nextline
8.4 +, \ and $ are all examples of __________.
a) special characters
b) strings
c) operators
d) literals
8.5 A string in C is __________.
a) an array of characters ending in the empty string
b) a sequence of characters contained within single quotes
c) a sequence of characters preceded by a length field
d) an array of characters ending in the null character
8.6 In C, it is appropriate to say that a string is a(n) __________.
a) pointer
b) integer
c) double quote
d) sequence of characters contained in single quotes
ANS: (a)
8.3 Character-Handling Library
8.7 The number 4 typically takes up _________ bit(s) when stored as a character on most of today’s computers.
(a) 1
(b) 2
(c) 3
(d) 8
8.8 The functions of the character-handling library typically manipulate characters as ___________.
(a) ints.
(b) floats.
(c) longs.
(d) bits.
8.9 The isxdigit (is hex digit) function would return false on
(a) a
(b) A
(c) 2
(d) g
8.10 Which character-handling library function returns a true value if its argument is a letter and 0 otherwise?
a) isalphanumeric
b) isalphabetic
c) isalpha
d) isletter
8.11 Which character-handling library function converts lowercase letters to uppercase letters?
a) lowertoupper
b) isupper
c) touppercase
d) toupper
8.12 Which of the following is not a whitespace character?
a) ‘\n’
b) ‘\f’
c) ‘\r’
d) ‘\w’
8.13 Which character handling library function returns true if its argument is a printing character?
a) ispchar
b) isprintablechar
c) isprint
d) isprintchar
8.4 String-Conversion Functions
8.14 The strtol and stroul functions do not
(a) need a special header file in order to be used.
(b) take three arguments.
(c) have to convert the entire string they are given.
(d) have the ability to output data in base 8.
8.15 The general utilities library is
a) stdutil
b) stdlibrary
c) stdutility
d) stdlib
8.16 Which statement is false?
a) Function atof returns a double version of its argument.
b) If the converted value cannot be represented, the behavior of atoi is undefined.
c) When using functions from the general utilities library, its header file must be included.
d) Function strtol receives three arguments.
8.17 __________ values can consist of the digits 0 through 9 and the letters A through F.
a) hexadecimal
b) binary
c) octal
d) decimal
8.5 Standard Input/Output Library Functions
8.18 Which function does not read data from standard input?
(a) scanf
(b) sscanf
(c) sprintf
(d) getchar
8.19 Function __________ inputs the next character from the standard input and re-turns it as an integer.
a) inputchr
b) getchr
c) inputchar
d) getchar
8.20 Function __________ prints the character equivalent of its integer argument.
a) putchar
b) putch
c) printchar
d) printch
8.21 Function fgets appends a __________ to its array target in memory.
a) leading null character
b) leading end-of-file character
c) terminating null character
d) terminating end-of-file character
8.22 Which statement is true?
a) sprintf takes its input from a character array.
b) sprintf prints its output in string format on the screen.
c) sprintf stores its output in a character array.
d) sprintf is a secure version of printf.
8.6 String-Manipulation Functions of the String-Handling Library
8.23 Which of the following does not necessarily append the null character to its result?
(a) strcpy
(b) strncpy
(c) strcat
(d) strncat
8.24 Which is not a capability of the string-handling library?
a) tokenizing strings
b) comparing strings
c) searching strings
d) inputting strings
8.25 Every function of the string handling library except for __________ appends the null character to its result.
a) strncpy
b) strncat
c) strcpy
d) strcat
8.26 The integral type of the value returned by operator sizeof is __________.
a) size-t
b) sizet
c) size.t
d) size_t
8.27 Which statement is false?
a) Function strcpy copies its first argument into its second argument.
b) Function strncpy does not necessarily copy the terminating null character of its second argument.
c) A common error is not appending a terminating null character to the first argument of a strncpy when the third argument is less than or equal to the length of the string in the second argument.
d) The first character of the second argument of strcat replaces the null character that terminates the string in the first argument.
ANS: (a)
8.7 Comparison Functions of the String-Handling Library
8.28 Assuming that string1 = “hello” and string2 = “hello world”, Which of the following returns 0?
(a) strcmp(string1, string2);
(b) strcmp(string1, string2, 6);
(c) strncmp(string1, string2, 6);
(d) strncmp(string1, string2, 5);
8.29 Function strcmp returns __________ if its first argument is equal to its second ar-gument.
a) specifically 1
b) any non-zero value (i.e., true)
c) specifically 0
d) any negative value
8.30 Function __________ compares up to n characters of its first argument with its second argument.
a) nstrcmp
b) strncmp
c) strcmpn
d) strcmp
8.31 ASCII and EBCDIC are
a) characters
b) strings
c) character sets
d) character comparison operators
8.32 When the computer compares two strings, it actually compares the __________ in the strings.
a) number of characters
b) numeric codes of the characters
c) character bits
d) lengths of the leading alphabetic portions
8.8 Search Functions of the String-Handling Library
8.33 strtok does not
(a) replace each delimiting character with ‘\0’
(b) return a pointer to the token it creates
(c) tokenize the entire a string when it’s called
(d) modify the input string
8.34 Which function would be the most useful for determining if a certain word is con-tained in a string representing a sentence?
(a) strcspn
(b) strchr
(c) strstr
(d) strrchr
8.35 What is the output of the following statement?
printf( “%s”, strspn( “Cows like to moo.”, “Ceiklosw ” );
(a) Nothing.
(b) 10
(c) 8
(d) e
8.36 Function __________ searches for the first occurrence of a character in a string.
a) firstchar
b) getfirst
c) firstchr
d) strchr
8.37 Function strcspn returns __________.
a) a length
b) a range of characters
c) the starting and ending positions of a range of characters
d) a char
8.38 Function __________ searches for the first occurrence in its first string argument of any character in its second string argument.
a) strfirst
b) strstr
c) firstany
d) strpbrk
8.39 Which statement about strtok is false?
a) It breaks a string into tokens.
b) Subsequent calls to continue tokenizing the same string contain NULL as the first ar-gument.
c) The length of the current token is returned by each call.
d) If there are no more tokens when the function is called, NULL is returned.
8.40 Which statement is true?
a) strtok modifies the input string.
b) strtok makes a backup copy of the input string.
c) The first argument of each call to strtok is the string being tokenized.
d) strtok works only with a set of four predefined delimiters.
ANS: (a)
8.9 Memory Functions of the String-Handling Library
8.41 The ___________ function allows characters of one part of a string to be copied into another part of the string.
(a) memchr
(b) memcmp
(c) memset
(d) memmove
8.42 memcmp would return ___________ for the call
memcmp(“Hi, how are you?”, “Hi, how are things?”, 6);
(a) -1
(b) a negative number.
(c) zero.
(d) a positive number.
8.43 To change the string “ABCDEFGHI” to “aaaaaFGHI” you would use the _________ function.
(a) memset
(b) memcmp
(c) memchr
(d) memcopy
8.44 Which statement about the memory functions of the string handling library is false?
a) The functions treat blocks of memory as strings.
b) The functions facilitate manipulating, comparing and searching blocks of memory.
c) The pointer parameters to these functions are defined void *.
d) A void * pointer cannot be dereferenced.
8.45 Which statement about function memcpy is false?
a) It copies a specified number of characters from the object pointed to by its second argument into the object pointed to by its first argument.
b) It can receive a pointer to any type of object.
c) The result of this function is defined even if the two objects overlap in memory.
d) Function memmove correctly handles the situation for which memcpy most notably fails.
8.46 What memory function of the string handling library copies an unsigned char into a specified number of the leading locations pointed to by its first argument?
a) memcpy
b) memmove
c) memset
d) memlead
8.10 Other Functions of the String-Handling Library
8.47 Function __________ takes an error number and creates an error message string.
(a) errorstr
(b) strerror
(c) badstr
(d) strfail
8.48 The strlen function returns ________.
(a) the number of characters in a string excluding the null character
(b) the number of characters in a string including the null character
(c) the ASCII representation of the character
(d) none of these
8.49 Which statement is false?
a) Function strerror takes an error number and creates an error message string.
b) Function strerror maps its integer argument into a full text string in a system-dependent manner
c) Function strlen determines the length of a string including the null character.
d) Function strerror does not display its string output.
8.11 Secure C Programming
Leave a reply