ACtE03 · Chapter 3Programming & Applications🏛️ Past Licensure QuestionID: 2f9cb2bf
Which of the following is the correct syntax for declaring a function that accepts a 2D array as a formal parameter in C?
Which of the following is the correct syntax for declaring a function that accepts a 2D array as a formal parameter in C?
Multiple Choice Options
- A✓ Correct Option
void function(int arr[][3]);
- B
void function(int arr[][]);
- C
void function(int arr[3][]);
- D
void function(int [][]arr);
Detailed Technical Solution & Explanation
In C, when passing a multi-dimensional array, the compiler must know the sizes of all dimensions except the first so it can compute pointer arithmetic offsets (offset = i * columns + j). Thus, int arr[][3] or int arr[3][3] is valid, but the second dimension can never be omitted.
Option Analysis:
•
Option A (;): Correct. The first dimension (rows) can be omitted, but the column dimension must be specified.
•
Option B (;): Invalid C syntax because column bounds are missing, preventing subscript offset calculation.
•
Option C (;): Invalid syntax; trailing dimensions cannot be left empty.
•
Option D (;): Java-style array notation; invalid in C.
Reference: Demo · Set 4NEC Licensure Syllabus