CH 8 To 11

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

CH 8 1.

. THE linear(or sequential) search algorithm steps sequentially through an array ,comparing each item with the search value. 2. The binary search algorithm repeatedly divides the portion of an array being searched in half. 3. The linear search algorithm is adequate for small arrays but not large arrays. 4. The binary search algorithm requires that the arrays contents be sorted. 5. If an array is sorted in ascending order, the values are stored from lowest to highest. 6. If an array is sorted in descending order, the values are stored from highest to lowest. 1. (T) If data are sorted in ascending order, it means they are ordered form lowest value to highest value. 2. (F) If data are sorted in descending order, it means they are ordered form lowest value to highest value. 3. (T) The average number of comparisons performed by the linear search on an array of N elements is N/2 (assuming the search values are consistently found). 4. (F) The maximum number of comparisons performed by the linear search on an array of N elements is N/2 (assuming the search values are consistently found). CH 9 1. Each byte in memory is assigned a unique address. 2. The address(&) operator can be used to determine a variables address. 3. Pointer variables are designed to hold addressed. 4. The indirection(*) operator can be used to work with the variable a pointer points to. 5. Array names can be used as pointers, and vice versa[]. 6. Creating variables while a program is running is called

Dynamically memory allocation[]. 7. The new operator is used to dynamically allocate memory. 8. Under older compilers, if the new operator cannot allocate the amount of memory requested, it returns 0 or null. 9. A pointer that contains the address 0 is called a null pointer. 10. When a program is finished with a chunk of dynamically allocated memory, it should free it with the delete operator. 11. You should only use pointers with delete that were previously used with new. 1. (T) Each byte of memory is assigned a unique address. 2. (F) The * operator is used to get the address of a variable. 3. (T) Pointer variables are designed to hold addresses. 4. (F) The & symbol is called the indirection operator. 5. (F) The & operator dereferences a pointer. 6. (T) When the indirection operator is used with a pointer variable, you are actually working with the value the pointer is pointing to. 7. (F) Array names cannot be dereferenced with the indirection operator. 8. (T) When you add a value to a pointer, you are actually adding that number times the size of the data type referenced by the pointer. 9. (T) The address operator is not needed to assign an arrays address to a pointer. 10. (F) You can change the address that an array name points to. 11. (F) Any mathematical operation, including multiplication and division, may be performed on a pointer. 12. (T) The new operator dynamically allocates memory. 13. (F) A pointer variable that has not been initialized is called a null pointer. 14. (T) The address 0 is generally considered unusable. 15. (F)In using a pointer with the delete operator, it is not necessary for the pointer to have been previously used with the new operator CH 10 1. The isupper function returns true if the character argument is

uppercase. 2. The isulpha function returns true if the character argument is a letter of the alphabet. 3. The isdigit function returns true if the character argument is a digit. 4. The isspace function returns true if the character argument is a whitespace character. 5. The toupper function returns the uppercase equivalent of its character argument. 6. The tolower function returns rthe lowercase equivalent of its character argument. 7. The cctype file must be included in a program that uses character testing functions. 8. The strlen function returns the length of a string. 9. The concatenate two strings means to append one string to the other. 10. The strcat function concatenates two strings. 11. The strcpy function copies one string to another. 12. The strstr function searches for a string inside of another one. 13. The strcmp function compares two strings. 14. The strncpy function copies, at most, n number of characters from one string to another. 15. The atoi function returns the value of a string converted to an integer. 16. The atol function returns the value of a string converted to a long integer. 17. The atof function returns the value of a string converted to a float. 18. The itoa function converts an integer to a string. 1. (F) Character testing functions, such as isupper, accept strings as arguments and test each character in the string. 2. (T) If touppers argument is already uppercase, it is returned as is, with no changes. 3. (F) If tolowers argument is already lowercase, it will be inadvertently converted to uppercase. 4. (F) The strlen function returns the size of the array containing a string.

5.

(T) If the starting address of a string is passed into a point parameter, it can be assumed that all the characters, from that address up to the byte that holds the null terminator, are part of the string. 6. (T) String-handling functions accept as arguments pointers to strings (array names or pointer variables), or literal strings. 7. (F) The strcat function checks to make sure the first string is large enough to hold both strings before performing the concatenation. 8. (T) The strcpy function will overwrite the contents of its first string argument. 9. (T) The strcpy function performs no bounds checking on the first agument. 10. (F) There is no difference between 847 and 847. CH 11 1. Before a structure variable can be created, the structure must be declared. 2. The tag is the name of the structure type. 3. The variables declared inside a structure declaration are called members. 4. A(n) semicolon is required after the closing brace of a structure declaration. 5. In the definition of a structure variable, the tag is placed before the variable name, just like the data type of a regular variable is placed before its name. 6. The dot operator allows you to access structure members. 1. (T) A semicolon is required after the closing brace of a structure or union declaration. 2. (T) A structure declaration does not define a variable. 3. (F) The contents of a structure variable can be displayed by passing the structure variable to the cout object. 4. (F) Structure variables may not be initialized. 5. (T) In a structure variables initialization list, you do not have to provide initializers for all the members. 6. (F) You may skip members in a structures initialization list.

7. 8. 9. 10. 11. 12. 13.

14. 15. 16. 17. 18. 19. 20. 21.

(F) The following expression refers to the element 5 in the array carInfo:carInfo.model[5] (T) An array of structures may be initialized. (F) A structure variable may not be a member of another structure. (T) A structure member variable may be passed to a function as an argument. (F) An entire structure may not be passed to a function as an argument. (T) A function may return a structure. (T) When a function returns a structure, it is always necessary for the function to have a local structure variable to hold the member values that are to be returned. (F) The indirection operator has higher precedence than the dot operator. (F) The structure pointer operator does not automatically dereference the structure pointer on its left. (F) In a union, all the members are stored in different memory locations. (F) All the members of a union may be used simultaneously. (T) You may define arrays of unions. (F) You may not define pointers to unions. (T) An anonymous union has no name. (T) If an anonymous union is defined globally (outside all functions), it must be declared static.

You might also like