2271C Final Study Guide pt.7

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

23. A function that modifies an array by using pointer arithmetic to process every value should have a parameter that is a) a nonconstant pointer to nonconstant data b) a nonconstant pointer to constant data c) a constant pointer to nonconstant data d) a constant pointer to constant data

a)

1. Pointers cannot be used to (a) find the address of a variable in memory. (b) reference values directly. (c) simulate call-by-reference. (d) manipulate dynamic data structures.

b)

16. The unary * and __________ are complements of one another. a) / b) ^ c) & d) |

c)

15. Which statement is generally false? a) Initializing pointers is optional. b) Dereferencing an uninitialized pointer could lead to a fatal execution time error. c) Deferencing an uninitialized pointer could accidentally modify important data. d) Derefencing an uninitialized pointer causes a syntax error.

d)

12. The statement y = &yPtr; a) assigns the address of the variable y to pointer variable yPtr. b) assigns the address of the variable yPtr to pointer variable y. c) is a compilation error. d) is a logic error.

b)

19. When calling a function with arguments that should be modified, the __________ of those arguments are passed. a) memory b) addresses c) values d) complements

b)

4. A non-pointer variable name __________ references a value and a pointer variable name __________ references a value. a) directly, directly b) directly, indirectly c) indirectly, directly d) indirectly, indirectly

b)

10. Three of the following expressions have the same value. Which of the following's value is different from the others? (a) *&Ptr (b) &*Ptr (c) *Ptr (d) Ptr

c)

13. Which statement is false? a) The operand of the address operator must be a variable. b) The address operator cannot be applied to constants or to expressions. c) The address operator can be applied to variables defined with the storage class register. d) The address operator can be applied to variables defined with the storage class static.

c)

18. Which statement is false? a) All function calls in C pass arguments call-by-value. b) Call-by-reference enables a called function to modify variables in the calling function. c) Call-by-value is always more efficient than call-by-reference. d) In C, programmers use pointers and the indirection operator to simulate call-by-reference.

c)

34. sizeof (a) is a binary operator (b) returns the total number of elements in an array (c) usually returns a double (d) returns the total number of bytes in an array

d)

46. If bPtr is assigned b (the name of an array), then array element b[3] can alternatively be referenced with the pointer expression __________. a) bPtr + 3 b) b[bPtr + 3] c) *b [bPtr + 3] d) *(bPtr + 3)

d)

57. What would be the output of the following program: # include <stdio.h> int main() { int *a, i = 50; float b[5] = { 1.00, 20.10, 30.50, 40.65, 50.5 }; float *bptr = &b[0]; a = &i; *a = *a+ 5; printf(" *a = %d\n", *a); printf(" *bptr = %f\n", *(bptr + 2)); }

*a = 55 *bptr = 30.500000 Press any key to continue . . .

25. What method should be used to pass an array to a function that does not modify the array and only looks at it using array subscript notation? a) A constant pointer to constant data. b) A constant pointer to nonconstant data. c) A nonconstant pointer to constant data. d) A nonconstant pointer to constant data.

a)

33. To pass an array to a function, specify: a. the name of the array without any brackets. b. the name of the array preceded by an empty pair of brackets. c. the name of the array followed by a pair of brackets including the size of the array. d. the name of the array followed by a pair of brackets including a number one less than the size of the array.

a)

6 Referencing a value through a pointer is called __________. a) interdiction b) indirection c) intermediation d) redirection

b)

7. Which statement about pointers is false? a) They can be defined to point to objects of any data type. b) The indirection operator * distributes to all comma-separated variable names in a definition. c) The letters Ptr in a pointer variable name are optional. d) A pointer may be initialized to 0, NULL or an address.

b)

14. Which statement is false? a) The unary * operator is called the indirection operator or the dereferencing operator. b) The operand of the unary * operator must be a pointer. c) The unary * operator returns the value of its operand. d) Placing a * operator before a pointer dereferences the pointer.

c)

17. When a compiler encounters a function parameter for a singlesubscripted array of the form int a[], it converts the parameter to (a) int a (b) int &a (c) int * a (d) int * const a

c)

26. Which statement is false? a) The const qualifier enables the programmer to inform the compiler that the value of a particular variable should not be modified. b) The const qualifier did not exist in early versions of C; it was added to the language by the ANSI C committee. c) Using the const qualifier typically violates the principle of least privilege d) Adding const to C programs that do not use it presents significant opportunities for improvement in the software engineering of that code.

c)

3. Pointers are variables that contain __________ as their values. a) strings b) flowlines c) memory addresses d) directions

c)

31. When a structure must be passed to a function, we can use pointers to constant data to get the performance of a call by __________ and the protection of a call by __________. a) value, value b) value, reference c) reference, value d) reference, reference

c)

35. Which of the following gives the number of elements in the array int r[]? (a) sizeof (r) (b) sizeof (*r) (c) sizeof (r) / sizeof (int) (d) sizeof (*r) / sizeof (int)

c)

39. Given that k is an integer array starting at location 2000, kPtr is a pointer to k, and each integer is stored in 4 bytes of memory, what location does kPtr + 3 point to? a) 2003 b) 2006 c) 2012 d) 2024

c)

40. A pointer cannot be assigned to a) another pointer of the same type b) a pointer to void c) a pointer of a type other than its own type and void d) any other pointer by using the cast operator

c)

56. What would be the output of the following program: #include <stdio.h> int main() { int a[5] = { 4,5,3,10,7}; int *p = a; printf("%d\n", *p); //value 4 printf("%d\n", p); p = p + 1; p = p + 1; printf("%d\n", *p); printf("%d\n", p); int b = 2; int *q = &b; *q = 3; printf("%d\n", b); printf("%d\n", q); return 0; }

4 3864676 3 3864684 3 3864652 Press any key to continue . . .

28. Which statement is false? a) If a value should not change in the body of a function to which it is passed, the value should be defined const to ensure that it is not accidentally modified. b) Attempts to modify the value of a variable defined const are caught at execution time. c) One way to pass a pointer to a function is to use a non-constant pointer to non-constant data. d) It is dangerous to pass a non-pointer into a pointer argument.

b)

37. An expression such as sizeof(arrayName) / sizeof(double) might typically be used to determine a) the size of an array b) the number of elements in an array c) the number of elements in half an array d) the size of an element of an array

b)

43.Which statement is false? a) A pointer can always be assigned to another pointer of the same type. b) A cast operator must always be used to convert the pointer on the right of an assignment to the pointer type on the left of the assignment. c) Variables of all pointer types can be assigned a pointer to void. d) A pointer to void can be assigned a pointer of any type.

b)

52. (*max)(num1, num2, num3); a) is the header for function max b) is a call to function max c) is the prototype for function max d) is part of a definition of a pointer to the function max

b)

11. The __________, or address operator, is a unary operator that returns the address of its operand. a) & b) && c) * d) **

a)

20. If array name arrayName is passed to a function, C automatically passes __________. a) &arrayName[0] b) arrayName[1] c) arrayName[0] d) *arrayName

a)

22. Which statement is false? a) It's necessary to include names of pointer arguments in function prototypes. b) A function receiving an address as an argument must define a pointer parameter to receive the address. c) The compiler does not distinguish between a function that receives a pointer and a function that receives a single-subscripted array. d) The function must "know" whether it is receiving a single-subscripted array or simply a single variable for which it is to perform simulated call by reference.

a)

29. The highest level of data access is granted by a a) non-constant pointer to non-constant data. b) non-constant pointer to constant data. c) constant pointer to non-constant data. d) constant pointer to constant data.

a)

38. Which of the following can have a pointer as an operand? a) ++ b) *= c) % d) /

a)

41. Comparing pointers and performing arithmetic on them is meaningless unless a) they point to members of the same array b) they point to arrays of the same type c) they point to arrays of equal size d) they point to different locations

a)

50. The following statement rand( ) % 6 will produce random numbers in the range: a) 0 to 5 b) 0 to 6 c) 1 to 5 d) 1 to 6

a)

54. Which statement about the parameter definition int (*compare)(int, int) is false? a) It defines a parameter that is a pointer to a function that receives two integer arguments and returns a pointer to an integer as a result. b) Parentheses are needed around *compare because * has a lower precedence than the parentheses enclosing the function parameters. c) Without the parentheses it would have defined a function that receives two integers and returns a pointer to an integer. d) The corresponding parameter in the function prototype would ordinarily be int (*)(int, int)

a)

24. A function that prints a string should have a parameter that's a a) nonconstant pointer to nonconstant data. b) nonconstant pointer to constant data. c) constant pointer to nonconstant data. d) constant pointer to constant data.

b)

27. Which of the following most closely reflects the principle of least privilege. a) Always grant a function at least enough access to the data in its parameters to accomplish its specified task. b) Always grant a function enough access to the data in its parameters to accomplish its specified task, but no more. c) Always grant a function the least amount of access to the data in its parameters. d) Never grant a function access to the data in its parameters.

b)

55. When a pointer is passed into a parameter for a function, C will automatically allocate memory for it, so I do not have to worry about it a) True b) False ANS: (b)

b)

42. Which statement is false? a) A pointer may be incremented or decremented. b) An integer may be added to a pointer. c) All operators normally used in arithmetic expressions, assignment expressions and comparison expressions are valid in conjunction with pointer variables. d) A pointer may not be added to a pointer.

c)

44. Assuming that t is an array and tPtr is a pointer to that array, what expression refers to the address of element 3? a) *(tPtr + 3) b) tPtr[3] c) &t[3] d) *(t + 3)

c)

47. A string array (a) stores an actual string in each of its elements (b) can only provide access to strings of a certain length (c) is actually an array of pointers (d) is always less memory efficient than an equivalent double-subscripted array

c)

9. The & operator can be applied to (a) constants (b) variables defined with the storage class register (c) variables defined with the storage class static (d) rvalues

c)

2. Pointers may be assigned which of the following? (a) all integer values (b) an address (c) NULL (d) both (b) and (c)

d)

21. When the __________ of a variable is passed to a function, the indirection operator (*) may be used in the function to modify the __________ at that location in the caller's memory. a) address, address b) value, address c) value, value d) address, value

d)

30. Which statement is false? a) Arrays and structures are aggregate data types. b) Structures in C are sometimes called records in other languages. c) A structure is capable of storing many related data items of different data types. d) Structures are always passed call by reference.

d)

32. The least access privilege is granted by a __________ pointer to __________ data. a) non-constant, non-constant b) non-constant, constant c) constant, non-constant d) constant, constant

d)

36. Which statement is false? a) Using global variables, instead of passing arguments, can increase program performance, but reduce effective software engineering. b) Hardcoding into a function the size of an array that will be passed as an argument rather than passing the size of the array as a parameter, reduces the software reusability of that function. c) sizeof is an operator that calculates the size of its argument in bytes at compile time. d) When applied to the name of an array, sizeof returns the number of elements in the array.

d)

45. Consider the following function: void reverse(char * string1, const char * string2) { int stringsize = sizeof(string1)/sizeof(char); *(string1 + stringsize - 1) = '\0'; string1 = string1 + stringsize - 2; for (; *string2 != '\0'; --string1, ++string2) { *string1 = *string2; } } What method does the function use to refer to array elements? a) array/subscript notation b) array/offset notation c) pointer/subscript notation d) pointer/offset notation

d)

48. Which statement is false? a) In C, a string is essentially a pointer to its first character. b) Arrays may contain pointers. c) Each entry in an array of strings is actually a pointer to the first character of a string. d) The size of an array of strings is the sum of the lengths of the strings.

d)

49. Which of the following does not initialize all of the array elements to 0? a) int b[2][2]; b[0][0] = b[0][1] = b[1][0] = b[1][1] = 0; b) int b[2][2] = {0}; c) int b[2][2]; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { b[i][j] = 0; } } d) all of the above initialize all of their elements to 0.

d)

5. The definition int *count; a) is a syntax error because only pointers can be defined with * notation. b) is a compile-time error. c) is a logic error. d) is a correct definition of integer pointer count.

d)

51. Which of the following is false with regard to pointers to functions? a) They contain the starting address of the function code. b) They're dereferenced in order to call the function. c) They can be stored in arrays. d) They cannot be assigned to other function pointers

d)

53. A pointer to a function contains __________. a) the address of the function's automatic variables b) the address of the function on the stack c) the address of the entry for that function in the System Function Table d) the address of the function in memory

d)

8. Which statement about pointers is false? a) A pointer with the value NULL points to nothing. b) NULL is a symbolic constant defined in the <stdio.h> header file. c) Initializing a pointer to 0 is equivalent to initializing a pointer to NULL, but NULL is preferred. d) The values 0 and 1 are the only values that can be assigned directly to a pointer variable.

d)


Kaugnay na mga set ng pag-aaral

ES 350 Test 2 Quizzes (Chapter 6-11)

View Set

CEH Certified Ethical Hacker Chapter 11

View Set

Factorial Designs - ANOVA, MANOVA, ANCOVA, Multiple Regression

View Set