107k views
3 votes
Which of the following statements regarding arrays and functions is TRUE?

A. It is possible to pass the whole array by value to a user-defined function
B. The extent of the second dimension of a two-dimensional array should be noted in the definition when used as a parameter to a user-defined function.
C. From the declaration of a user-defined function it can be determined whether an element of an array is one of it s parameters.
D. None of the above.

User Barrymac
by
7.4k points

1 Answer

1 vote

Final answer:

Option B is true because for a two-dimensional array as a parameter in a function, the size of the second dimension must be specified for the compiler to correctly access elements. A is false because arrays are passed by reference, not value. C is false because a function declaration doesn't show if an argument is an array element.

Step-by-step explanation:

The correct answer to the question is B. The extent of the second dimension of a two-dimensional array should be noted in the definition when used as a parameter to a user-defined function. This is a requirement in languages like C and C++ because while the size of the first dimension can be ignored, the compiler needs to know the size of the second (and any subsequent) dimensions to correctly access array elements.

Option A is incorrect because in C and C++, arrays are always passed by reference, not by value, to functions. Option C is also incorrect because from the declaration of a user-defined function alone, it cannot be determined whether an array element is one of its parameters; you can only determine the type of the parameter (e.g., an array of a specific type).

User Brad Barrow
by
7.9k points