4.4.1 - Passing Array to Function.
1. What is an array in programming?
Correct Answer: (B) A collection of variables of the same type.
2. How do you declare a one-dimensional array in C?
Correct Answer: (B) int arr[5];
3. Which of the following accesses the third element of an array named arr?
Correct Answer: (A) arr[2]
4. What will be the output of the following code?
int arr[3] = {1, 2, 3}; printf("%d", arr[1]);
Correct Answer: (B) 2
5. What is the result of trying to access an out-of-bounds index in an array?
Correct Answer: (C) It leads to undefined behavior.
6. Which of the following statements correctly passes an array to a function in C?
Correct Answer: (A) func(arr);
7. How do you define a two-dimensional array with 3 rows and 4 columns?
Correct Answer: (A) int arr[3][4];
8. What is the output of the following code?
int arr[3] = {5, 10, 15}; printf("%d", arr[0] + arr[2]);
Correct Answer: (D) 20
9. Which function is used to determine the size of an array in bytes?
Correct Answer: (A) sizeof(array)
10. What is the primary advantage of using arrays?
Correct Answer: (B) Ease of manipulation and retrieval of data.
11. Which of the following correctly initializes an array with values?
Correct Answer: (A) int arr[] = {1, 2, 3};
12. Which of the following can be used to access the elements of a two-dimensional array?
Correct Answer: (B) Two indices.
13. What will happen if you declare an array with a size of 0 in C?
Correct Answer: (C) It will compile but cannot be used.
14. How do you pass an individual element of an array to a function?
Correct Answer: (B) func(arr[i]);
15. In which scenario is using an array more efficient than using separate variables?
Correct Answer: (C) When the number of variables is large and of the same type.
16. What will be the output of the following code?
int arr[3] = {2, 4, 6}; printf("%d", arr[0] * arr[1]);
Correct Answer: (B) 8
17. What does the following declaration represent?
int (*ptr)[5];
Correct Answer: (B) Pointer to an array of 5 integers.
18. Which of the following correctly accesses the last element of an array named arr with 5 elements?
Correct Answer: (A) arr[4]
19. How do you dynamically allocate memory for an array of 10 integers?
Correct Answer: (B) int *arr = malloc(10 * sizeof(int));
20. What will happen if you try to assign a new value to an element of an array declared as const?
Correct Answer: (B) It will cause a compilation error.