In C, when passing arrays to functions, what is actually passed?
AA copy of all array elements
BThe address of the first element (pointer)
CThe array size
DAll array elements and size
Correct Answer:
B. The address of the first element (pointer)
Explanation:
When an array is passed to a function in C, it decays to a pointer pointing to the first element. This is why changes made in the function affect the original array.
Which of the following is a correct way to initialize a 1D array in C?
Aint arr[5] = {1, 2, 3, 4, 5};
Bint arr[] = {1, 2, 3, 4, 5};
Cint arr[5];
DAll of the above
Correct Answer:
D. All of the above
Explanation:
All three methods are valid. Option A initializes with size 5, option B auto-determines size from initialization, and option C declares without initialization.