Deck 22: Bits, Characters, C Strings and Structs

Full screen (f)
exit full mode
Question
__________ is not allowed.

A) Accessing individual bits in a multi-bit bit field.
B) Padding a bit field with bits that cannot be accessed.
C) Having an unnamed bit field.
D) Having a bit field with a zero width.
Use Space or
up arrow
down arrow
to flip the card.
Question
Evaluate (00001000 & 11000101) ^ (11110000).

A) 00001101
B) 11000000
C) 00111101
D) 11110000
Question
The functions of the character-handling library typically manipulate characters as:

A) ints
B) floats
C) longs
D) chars
Question
Structure variable declarations can be incorporated into a structure definition by placing a comma-separated list of variable names:

A) After struct StructureName and before the left brace.
B) After the left brace and before the member declarations.
C) After the member declarations and before the right brace.
D) After the right brace and before the semicolon.
Question
Arrays are:

A) Always passed by reference.
B) Passed by reference unless inside a structure.
C) Passed by reference unless their elements are structures.
D) Always passed by value.
Question
Which of the following statements is false?

A) Names for structure types are often defined with typedef to create more readable type names.
B) The statement
Typedef Card* CardPtr;
Defines the new type name CardPtr as a synonym for type Card*.
C) Creating a new name with typedef does not create a new type; typedef simply creates a new type name that can then be used in the program as an alias for an existing type name.
D) C++11 added the keyword using as another mechanism for creating type aliases. The following declaration is equivalent to the typedef in part b):
Using Card* = CardPtr;
Question
The isxdigit function would return false on:

A) a
B) A
C) 2
D) g
Question
Typedef is used to:

A) Create a type name that is an alias for another type name.
B) Make a struct private.
C) Cast one struct to another type.
D) Initialize struct members.
Question
A bit field must be declared as a:

A) int or unsigned.
B) char.
C) float.
D) long.
Question
Which of the statements a), b) and c) is false?

A) To create a binary literal, precede a sequence of 1s and 0s with 0b or 0B.
B) You can define a 32-bit mask as
0b10000000'00000000'00000000'00000000
C) The literal in part b) uses C++14's single-quote character to separate groups of digits for readability.
D) All of the above statements are true.
Question
Let x be an unsigned int on a machine with 4-byte unsigned ints. What effect does x>>=1;
X<<=1;
Have?

A) There is no effect.
B) The leftmost bit of x is set to 0.
C) The rightmost bit of x is set to 0.
D) Both (b) and (c).
Question
Which is the proper way to create a built-in array of structure variables of type Data?

A) MyArray Data[10]
B) Data MyArray[10];
C) Data struct myArray[10];
D) struct MyArray[Data];
Question
The main difference between structures and classes is:

A) Whether they default to public or private access.
B) How they access member variables.
C) That classes always require new be used with them while structures do not.
D) There is no difference between structures and classes.
Question
For any nonzero 8-bit x, which of the following does not result in zero?

A) x &= (~x)
B) x ^= x
C) x <<= 8
D) x |= x
Question
The advantages of using typedef do not include:

A) Making programs more portable by allowing data types to be easily changed to meet system specifications.
B) Making type names shorter.
C) Making programs more readable.
D) Increasing the efficiency of accessing struct member variables.
Question
Let Bit1 = Bit2 = 1. Which of the following does not have the same result as the others?

A) Bit1 & Bit2
B) Bit1 | Bit2
C) Bit1 ^ Bit2
D) ~(~Bit2)
Question
Which of the following is not a bitwise operator?

A) ^
B) >>
C) ~
D) *
Question
Two structure variables of the same type with the same member values, when compared will:

A) Always compare equally.
B) Never compare equally.
C) Sometimes compare equally.
D) Result in a compile error.
Question
The most basic unit of data on a computer is the:

A) Bit.
B) Byte.
C) File.
D) int.
Question
The number of bits in a bit field is specified with:

A) Parentheses as in bitfield(4)
B) A colon as in bitfield : 4
C) Brackets as in bitfield[4]
D) A dot as in bitfield.4
Question
The main difference between the functions atof, atoi and atol is:

A) Their return types.
B) Their arguments.
C) Their header files.
D) Their efficiency.
Question
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, 5);.
D) strncmp(string1, string2, 6);.
Question
The ___________ function allows characters of one part of a string to be copied into another, overlapping part of the same string.

A) memchr
B) memcmp
C) memcpy
D) memmove
Question
Which function would be the most useful for determining if a certain word is contained in a string representing a sentence?

A) strcspn.
B) strchr.
C) strstr.
D) strrchr.
Question
Strtok does not:

A) Replace each delimiting character with '\0'.
B) Return a pointer to the token it creates.
C) Completely tokenize the string the first time it is called.
D) Modify the input string.
Question
Memcmp would return ___________ for the call memcmp("Hi, how are you?", "Hi, how are things?", 6).

A) 1
B) A positive number.
C) 0
D) A negative number.
Question
Which of the following correctly copies the contents of string2 into string1? Assume that string2 is equal to "goodbye" and string1 is equal to "good morning"?

A) strcpy(string1, string2);.
B) strcpy(string1, string2, 6);.
C) Strncpy(string1, string2, 5);.
D) strncpy(string1, string2, 6);.
Question
To change the string "ABCDEFGHI" to "aaaaaFGHI" you would use the _________ function.

A) memset
B) memcmp
C) memchr
D) memcopy
Question
The strtol and stroul functions do not:

A) Need a header file to be used.
B) Take three arguments.
C) Have the same return types.
D) Have the ability to return data in base 8.
Question
What is the output of the following statement? cout << strspn("Cows like to moo.", "Ceik losw");

A) Nothing.
B) 10.
C) 8.
D)
E)
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/30
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 22: Bits, Characters, C Strings and Structs
1
__________ is not allowed.

A) Accessing individual bits in a multi-bit bit field.
B) Padding a bit field with bits that cannot be accessed.
C) Having an unnamed bit field.
D) Having a bit field with a zero width.
A
2
Evaluate (00001000 & 11000101) ^ (11110000).

A) 00001101
B) 11000000
C) 00111101
D) 11110000
D
3
The functions of the character-handling library typically manipulate characters as:

A) ints
B) floats
C) longs
D) chars
A
4
Structure variable declarations can be incorporated into a structure definition by placing a comma-separated list of variable names:

A) After struct StructureName and before the left brace.
B) After the left brace and before the member declarations.
C) After the member declarations and before the right brace.
D) After the right brace and before the semicolon.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
5
Arrays are:

A) Always passed by reference.
B) Passed by reference unless inside a structure.
C) Passed by reference unless their elements are structures.
D) Always passed by value.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
6
Which of the following statements is false?

A) Names for structure types are often defined with typedef to create more readable type names.
B) The statement
Typedef Card* CardPtr;
Defines the new type name CardPtr as a synonym for type Card*.
C) Creating a new name with typedef does not create a new type; typedef simply creates a new type name that can then be used in the program as an alias for an existing type name.
D) C++11 added the keyword using as another mechanism for creating type aliases. The following declaration is equivalent to the typedef in part b):
Using Card* = CardPtr;
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
7
The isxdigit function would return false on:

A) a
B) A
C) 2
D) g
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
8
Typedef is used to:

A) Create a type name that is an alias for another type name.
B) Make a struct private.
C) Cast one struct to another type.
D) Initialize struct members.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
9
A bit field must be declared as a:

A) int or unsigned.
B) char.
C) float.
D) long.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
10
Which of the statements a), b) and c) is false?

A) To create a binary literal, precede a sequence of 1s and 0s with 0b or 0B.
B) You can define a 32-bit mask as
0b10000000'00000000'00000000'00000000
C) The literal in part b) uses C++14's single-quote character to separate groups of digits for readability.
D) All of the above statements are true.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
11
Let x be an unsigned int on a machine with 4-byte unsigned ints. What effect does x>>=1;
X<<=1;
Have?

A) There is no effect.
B) The leftmost bit of x is set to 0.
C) The rightmost bit of x is set to 0.
D) Both (b) and (c).
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
12
Which is the proper way to create a built-in array of structure variables of type Data?

A) MyArray Data[10]
B) Data MyArray[10];
C) Data struct myArray[10];
D) struct MyArray[Data];
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
13
The main difference between structures and classes is:

A) Whether they default to public or private access.
B) How they access member variables.
C) That classes always require new be used with them while structures do not.
D) There is no difference between structures and classes.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
14
For any nonzero 8-bit x, which of the following does not result in zero?

A) x &= (~x)
B) x ^= x
C) x <<= 8
D) x |= x
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
15
The advantages of using typedef do not include:

A) Making programs more portable by allowing data types to be easily changed to meet system specifications.
B) Making type names shorter.
C) Making programs more readable.
D) Increasing the efficiency of accessing struct member variables.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
16
Let Bit1 = Bit2 = 1. Which of the following does not have the same result as the others?

A) Bit1 & Bit2
B) Bit1 | Bit2
C) Bit1 ^ Bit2
D) ~(~Bit2)
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
17
Which of the following is not a bitwise operator?

A) ^
B) >>
C) ~
D) *
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
18
Two structure variables of the same type with the same member values, when compared will:

A) Always compare equally.
B) Never compare equally.
C) Sometimes compare equally.
D) Result in a compile error.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
19
The most basic unit of data on a computer is the:

A) Bit.
B) Byte.
C) File.
D) int.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
20
The number of bits in a bit field is specified with:

A) Parentheses as in bitfield(4)
B) A colon as in bitfield : 4
C) Brackets as in bitfield[4]
D) A dot as in bitfield.4
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
21
The main difference between the functions atof, atoi and atol is:

A) Their return types.
B) Their arguments.
C) Their header files.
D) Their efficiency.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
22
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, 5);.
D) strncmp(string1, string2, 6);.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
23
The ___________ function allows characters of one part of a string to be copied into another, overlapping part of the same string.

A) memchr
B) memcmp
C) memcpy
D) memmove
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
24
Which function would be the most useful for determining if a certain word is contained in a string representing a sentence?

A) strcspn.
B) strchr.
C) strstr.
D) strrchr.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
25
Strtok does not:

A) Replace each delimiting character with '\0'.
B) Return a pointer to the token it creates.
C) Completely tokenize the string the first time it is called.
D) Modify the input string.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
26
Memcmp would return ___________ for the call memcmp("Hi, how are you?", "Hi, how are things?", 6).

A) 1
B) A positive number.
C) 0
D) A negative number.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
27
Which of the following correctly copies the contents of string2 into string1? Assume that string2 is equal to "goodbye" and string1 is equal to "good morning"?

A) strcpy(string1, string2);.
B) strcpy(string1, string2, 6);.
C) Strncpy(string1, string2, 5);.
D) strncpy(string1, string2, 6);.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
28
To change the string "ABCDEFGHI" to "aaaaaFGHI" you would use the _________ function.

A) memset
B) memcmp
C) memchr
D) memcopy
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
29
The strtol and stroul functions do not:

A) Need a header file to be used.
B) Take three arguments.
C) Have the same return types.
D) Have the ability to return data in base 8.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
30
What is the output of the following statement? cout << strspn("Cows like to moo.", "Ceik losw");

A) Nothing.
B) 10.
C) 8.
D)
E)
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 30 flashcards in this deck.