Correct Answer: A data structure that can hold multiple values of the same type
Explanation: An array in C is a data structure that can store a fixed-size sequence of elements of the same data type.
Correct Answer: int array[10];
Explanation: The correct syntax to declare an integer array of size 10 in C is `int array[10];`.
Correct Answer: All of the above
Explanation: In C, an array can be initialized to zero using any of these methods. If only one zero is provided, the remaining elements are automatically initialized to zero.
Correct Answer: 0
Explanation: In C, the indexing of array elements starts from 0, so the first element is at index 0.
Correct Answer: numbers[2];
Explanation: Arrays in C are zero-indexed, so the third element is accessed with index 2.
#include <stdio.h>
int array[5] = {1, 2, 3, 4, 5};
printf("%d", array[2]);
Correct Answer: 3
Explanation: The array `array` has its elements indexed from 0 to 4. `array[2]` refers to the third element, which is 3.
Correct Answer: int array[3][4];
Explanation: The correct syntax to define a two-dimensional array of integers in C is `int array[3][4];`.
Correct Answer: matrix[1][2];
Explanation: In a two-dimensional array, the first index is the row, and the second index is the column. Since indexing starts from 0, `matrix[1][2]` accesses the second row and third column.
#include <stdio.h>
int arr[4] = {10, 20, 30, 40};
int sum = 0;
for(int i = 0; i < 4; i++) {
sum += arr[i];
}
printf("%d", sum);
Correct Answer: 100
Explanation: The code sums up all elements of the array `arr`, resulting in 10 + 20 + 30 + 40 = 100.
#include <stdio.h>
int arr[][3] = {{1, 2, 3}, {4, 5, 6}};
Correct Answer: A two-dimensional array with 2 rows and 3 columns
Explanation: This declaration defines a two-dimensional array with 2 rows and 3 columns, where the elements are specified in the initialization list.
#include <stdio.h>
int arr[10];
Correct Answer: 40 bytes
Explanation: The size of the array `arr` is 10 integers, and each integer is 4 bytes. Therefore, the total size is 10 * 4 = 40 bytes.
Correct Answer: All of the above
Explanation: All the given options correctly initialize an array. The first and second explicitly specify the size, while the third initializes the first three elements and the rest are initialized to zero.
Correct Answer: sizeof()
Explanation: The `sizeof()` operator in C is used to determine the size of a variable or an array in bytes.
#include <stdio.h>
int arr[3] = {10, 20, 30};
printf("%d", arr[3]);
Correct Answer: Undefined behavior
Explanation: Accessing `arr[3]` is out of bounds since the valid indices for `arr` are 0, 1, and 2. This results in undefined behavior.
Correct Answer: arr[4] = 50;
Explanation: In a zero-indexed array of size 5, the last element is at index 4. Thus, `arr[4] = 50;` correctly assigns the value 50 to the last element.
Correct Answer: All of the above
Explanation: All these methods correctly initialize an array of size 5 with all elements set to zero.
#include <stdio.h>
int arr[] = {5, 10, 15, 20};
printf("%d", arr[1] + arr[3]);
Correct Answer: 30
Explanation: `arr[1]` is 10 and `arr[3]` is 20. The sum is 10 + 20 = 30.
Correct Answer: By reference
Explanation: In C, arrays are passed to functions by reference, meaning the address of the first element is passed, not the entire array.
#include <stdio.h>
int arr[] = {1, 2, 3, 4, 5};
int *p = arr;
printf("%d", *(p + 2));
Correct Answer: 3
Explanation: `p` points to the first element of `arr`. `*(p + 2)` dereferences the pointer to the third element, which is 3.
#include <stdio.h>
int arr[5] = {0};
Correct Answer: An array of 5 integers, all initialized to zero
Explanation: The declaration initializes an array of 5 integers, where all elements are set to zero because only the first element is explicitly initialized, and the rest are implicitly set to zero.
Correct Answer: int arr[3][4];
Explanation: The correct syntax to declare a two-dimensional array of integers with 3 rows and 4 columns in C is `int arr[3][4];`.
Correct Answer: All of the above
Explanation: Each of these statements initializes all elements of a 3x3 two-dimensional array to zero.
Correct Answer: arr[1][2]
Explanation: Since array indexing starts at 0, `arr[1][2]` accesses the element in the second row and third column.
#include <stdio.h>
int arr[2][3] = {{1, 2, 3}, {4, 5, 6}};
printf("%d", arr[1][1]);
Correct Answer: 5
Explanation: `arr[1][1]` accesses the element in the second row and second column, which is 5.
Correct Answer: int arr[2][2] = {{1, 2}, {3, 4}};
Explanation: The correct way to initialize a 2x2 array with these elements is to use nested curly braces to separate the rows.
#include <stdio.h>
int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int sum = 0;
for(int i = 0; i < 3; i++) {
sum += arr[i][i];
}
printf("%d", sum);
Correct Answer: 15
Explanation: The code sums the diagonal elements of the array: 1 + 5 + 9 = 15.
Correct Answer: arr[0][1] = 10;
Explanation: In a zero-indexed two-dimensional array, `arr[0][1]` refers to the first row and second column.
#include <stdio.h>
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
// Access arr[i][j]
#include <stdio.h>
for(int i = 0; i < 2; i++)
// Access arr[i][i]
#include <stdio.h>
for(int j = 0; j < 2; j++)
// Access arr[j][j]
#include <stdio.h>
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
// Access arr[j][i]
Correct Answer:
#include <stdio.h>
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
// Access arr[i][j]
Explanation: To iterate through all elements of a 2x2 array, you need nested loops where the outer loop iterates over rows and the inner loop iterates over columns.
#include <stdio.h>
int arr[2][2] = {{1, 2}, {3, 4}};
printf("%d", arr[0][0] + arr[1][1]);
Correct Answer: 5
Explanation: `arr[0][0]` is 1 and `arr[1][1]` is 4. The sum is 1 + 4 = 5.
Correct Answer: The elements are stored in a single contiguous block of memory, row-wise.
Explanation: In C, a two-dimensional array is stored in a single contiguous block of memory, with elements laid out row-wise.
Correct Answer: int arr[2][3][4];
Explanation: The correct syntax to declare a three-dimensional array of integers with dimensions 2x3x4 in C is `int arr[2][3][4];`.
Correct Answer: int arr[2][2][2] = {{{1, 1}, {1, 1}}, {{1, 1}, {1, 1}}};
Explanation: The correct way to initialize a 2x2x2 three-dimensional array with all elements set to 1 is to use nested curly braces for each dimension.
Correct Answer: arr[0][1][2]
Explanation: In a zero-indexed three-dimensional array, `arr[0][1][2]` accesses the element in the first row, second column, and third depth.
#include <stdio.h>
int arr[2][2][2] = {{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}};
printf("%d", arr[1][0][1]);
Correct Answer: 6
Explanation: `arr[1][0][1]` accesses the element in the second row, first column, and second depth, which is 6.
#include <stdio.h>
int sum = 0;
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
for(int k = 0; k < 2; k++)
sum += arr[i][j][k];
#include <stdio.h>
int sum = 0;
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
sum += arr[i][j];
#include <stdio.h>
int sum = 0;
for(int i = 0; i < 2; i++)
sum += arr[i];
#include <stdio.h>
int sum = 0;
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
for(int k = 0; k < 2; k++)
sum += arr[j][i][k];
Correct Answer:
#include <stdio.h>
int sum = 0;
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
for(int k = 0; k < 2; k++)
sum += arr[i][j][k];
Explanation: To sum all elements in a 2x2x2 three-dimensional array, nested loops are needed for each dimension.
Correct Answer: Contiguous block of memory, row-major order
Explanation: In C, multidimensional arrays are stored in a single contiguous block of memory in row-major order, meaning the rightmost index varies the fastest.
Correct Answer: sizeof(arr) / sizeof(arr[0][0][0])
Explanation: The total number of elements in the array is the total size divided by the size of one element. `sizeof(arr) / sizeof(arr[0][0][0])` gives the number of elements.
#include <stdio.h>
int arr[2][2][2] = {{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}};
printf("%d", arr[0][1][1] + arr[1][1][0]);
Correct Answer: 10
Explanation: `arr[0][1][1]` is 4 and `arr[1][1][0]` is 7. The sum is 4 + 7 = 11.
Correct Answer: arr[1][0][0] = 9;
Explanation: In a zero-indexed three-dimensional array, `arr[1][0][0]` refers to the second row, first column, and first depth.
Correct Answer: int arr[2][2][2][2];
Explanation: The correct syntax to declare a four-dimensional array of integers with dimensions 2x2x2x2 in C is `int arr[2][2][2][2];`.
Correct Answer: int arr[5] = {1, 2, 3, 4, 5};
Explanation: The correct syntax to initialize an array of 5 integers with these values is `int arr[5] = {1, 2, 3, 4, 5};`.
#include <stdio.h>
int arr[5] = {1, 2};
Correct Answer: {1, 2, 0, 0, 0}
Explanation: When an array is partially initialized, the remaining elements are set to zero.
Correct Answer: Both A and C
Explanation: Both `int arr[10] = {0};` and `int arr[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};` correctly initialize all elements to zero.
Correct Answer: int arr[2][3] = {{1, 2, 3}, {4, 5, 6}};
Explanation: The correct syntax to initialize a two-dimensional array with these values is `int arr[2][3] = {{1, 2, 3}, {4, 5, 6}};`.
#include <stdio.h>
int arr[4] = {0, 1, [3] = 3};
Correct Answer: {0, 1, 0, 3}
Explanation: This code uses designated initializers. The value at index 3 is explicitly set to 3, and the unspecified element at index 2 is initialized to 0.
Correct Answer: All of the above
Explanation: All these methods correctly initialize a character array with the string "Hello". Option A uses a character array with a null terminator, while B and C use string literals which automatically add the null terminator.
Correct Answer: If an array is partially initialized, the remaining elements are automatically initialized to zero.
Explanation: In C, if an array is partially initialized, the unspecified elements are automatically initialized to zero.
#include <stdio.h>
int arr[3] = {1, 2};
printf("%d", arr[2]);
Correct Answer: 0
Explanation: Since the array is partially initialized, the third element `arr[2]` is automatically set to 0.
Correct Answer: float arr[4] = {1.1, 2.2, 3.3, 4.4};
Explanation: The correct syntax to initialize a float array with these values is `float arr[4] = {1.1, 2.2, 3.3, 4.4};`.
#include <stdio.h>
int arr[5] = {[2] = 5, [4] = 10};
printf("%d %d %d %d %d", arr[0], arr[1], arr[2], arr[3], arr[4]);
Correct Answer: 0 0 5 0 10
Explanation: The code uses designated initializers to set `arr[2]` to 5 and `arr[4]` to 10. The remaining elements are initialized to 0.
Correct Answer: Shift the elements from the specified position to the right
Explanation: To insert an element into an array at a specific position, you need to shift the elements from that position to the right to make space for the new element.
Correct Answer: All of the above
Explanation: You can traverse an array using any of these loops: while loop, do-while loop, or for loop.
Correct Answer: O(n)
Explanation: Inserting an element at the beginning of an array requires shifting all existing elements to the right, which takes O(n) time.
Correct Answer: Shift the elements from the specified position to the left
Explanation: To delete an element from an array at a specific position, you need to shift the elements from that position to the left to fill the gap.
#include <stdio.h>
int arr[5] = {1, 2, 3, 4, 5};
for (int i = 0; i < 5; i++) {
printf("%d ", arr[i]);
}
Correct Answer: 1 2 3 4 5
Explanation: The code traverses the array and prints each element, resulting in the output "1 2 3 4 5".
Correct Answer: O(1)
Explanation: Deleting an element from the end of an array is a constant time operation, O(1), since no elements need to be shifted.
#include <stdio.h>
int arr[5] = {1, 2, 3, 4, 5};
for (int i = 3; i < 5; i++) {
arr[i - 1] = arr[i];
}
Correct Answer: {1, 2, 3, 5, 5}
Explanation: The code shifts elements starting from index 3 to the left, resulting in `arr[2] = 4` and `arr[3] = 5`.
#include <stdio.h>
for (int i = n; i > pos; i--) {
arr[i] = arr[i - 1];
}
arr[pos] = x;
#include <stdio.h>
for (int i = n - 1; i >= pos; i--) {
arr[i] = arr[i - 1];
}
arr[pos] = x;
#include <stdio.h>
for (int i = n - 1; i >= pos; i--) {
arr[i + 1] = arr[i];
}
arr[pos] = x;
#include <stdio.h>
for (int i = pos; i < n; i++) {
arr[i + 1] = arr[i];
}
arr[pos] = x;
Correct Answer:
#include <stdio.h>
for (int i = n - 1; i >= pos; i--) {
arr[i + 1] = arr[i];
}
arr[pos] = x;
Explanation: This code shifts elements to the right starting from the end of the array, making space for the new element at position `pos`.
Correct Answer: O(n)
Explanation: Traversing an array requires visiting each element once, resulting in a time complexity of O(n).
Correct Answer: arr[2] = x;
Explanation: Array indexing starts at 0, so the third position corresponds to index 2.
#include <stdio.h>
int arr[6] = {1, 2, 3, 4, 5, 6};
for (int i = 0; i < 6; i += 2) {
printf("%d ", arr[i]);
}
Correct Answer: 1 3 5
Explanation: The loop increments `i` by 2 each time, so it prints the elements at even indices: 1, 3, and 5.
#include <stdio.h>
int arr[6] = {1, 2, 3, 4, 5, 6};
for (int i = 1; i < 6; i++) {
arr[i - 1] = arr[i];
}
Correct Answer: {2, 3, 4, 5, 6, 6}
Explanation: The loop shifts elements to the left starting from index 1, resulting in `arr[5]` being duplicated.
#include <stdio.h>
for (int i = pos; i < n; i++) {
arr[i] = arr[i + 1];
}
#include <stdio.h>
for (int i = pos; i < n - 1; i++) {
arr[i] = arr[i + 1];
}
#include <stdio.h>
for (int i = pos; i < n - 1; i++) {
arr[i + 1] = arr[i];
}
#include <stdio.h>
for (int i = pos; i < n; i++) {
arr[i + 1] = arr[i];
}
Correct Answer:
#include <stdio.h>
for (int i = pos; i < n - 1; i++) {
arr[i] = arr[i + 1];
}
Explanation: This code shifts elements to the left starting from position `pos`, effectively removing the element at that position.
Correct Answer: O(n)
Explanation: Deleting an element from the beginning of an array requires shifting all subsequent elements to the left, which takes O(n) time.
#include <stdio.h>
int arr[5] = {1, 2, 3, 4, 5};
for (int i = 4; i >= 0; i--) {
printf("%d ", arr[i]);
}
Correct Answer: 5 4 3 2 1
Explanation: The loop traverses the array in reverse order, printing each element.
Correct Answer: Accessing and processing each element in the array
Explanation: Array traversal is used to access and process each element in the array.
#include <stdio.h>
int arr[6] = {1, 2, 3, 4, 5, 6};
int pos = 3;
int x = 10;
for (int i = 5; i >= pos; i--) {
arr[i + 1] = arr[i];
}
arr[pos] = x;
Correct Answer: {1, 2, 3, 4, 10, 5, 6}
Explanation: The code shifts elements to the right starting from index 5 to make space for the new element `x` at position 3.
Correct Answer: O(n)
Explanation: Inserting an element into a sorted array requires finding the correct position (O(log n)) and then shifting elements to make space (O(n)), resulting in an overall complexity of O(n).
#include <stdio.h>
for (int i = n - 1; i >= 0; i--) {
printf("%d ", arr[i]);
}
#include <stdio.h>
for (int i = 0; i < n; i++) {
printf("%d ", arr[n - i - 1]);
}
Correct Answer: Both A and B
Explanation: Both methods correctly traverse the array in reverse order and print each element.
#include <stdio.h>
int pos;
for (pos = 0; pos < n; pos++) {
if (arr[pos] == x) break;
}
for (int i = pos; i < n - 1; i++) {
arr[i] = arr[i + 1];
}
#include <stdio.h>
int pos;
for (pos = 0; pos < n; pos++) {
if (arr[pos] == x) break;
}
for (int i = pos + 1; i < n; i++) {
arr[i - 1] = arr[i];
}
Correct Answer: Both A and B
Explanation: Both methods correctly find the first occurrence of `x` and shift elements to the left to remove it.
#include <stdio.h>
int arr[5] = {1, 2, 3, 4, 5};
int x = 3;
int pos;
for (pos = 0; pos < 5; pos++) {
if (arr[pos] == x) break;
}
for (int i = pos; i < 4; i++) {
arr[i] = arr[i + 1];
}
Correct Answer: {1, 2, 4, 5, 5}
Explanation: The code finds the first occurrence of `x` and shifts elements to the left, but doesn't handle the last element properly.
Correct Answer: O(m * n)
Explanation: Traversing a two-dimensional array requires visiting each element once, resulting in a time complexity of O(m * n).
#include <stdio.h>
int arr[4] = {1, 2, 3, 4};
for (int i = 0; i < 4; i++) {
printf("%d ", arr[3 - i]);
}
Correct Answer: 4 3 2 1
Explanation: The loop prints the elements in reverse order.
#include <stdio.h>
int max = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] > max) max = arr[i];
}
printf("%d", max);
#include <stdio.h>
int max = arr[0];
for (int i = 0; i < n; i++) {
if (arr[i] > max) max = arr[i];
}
printf("%d", max);
#include <stdio.h>
int max = arr[1];
for (int i = 1; i < n; i++) {
if (arr[i] > max) max = arr[i];
}
printf("%d", max);
#include <stdio.h>
int max = arr[0];
for (int i = 1; i <= n; i++) {
if (arr[i] > max) max = arr[i];
}
printf("%d", max);
Correct Answer:
#include <stdio.h>
int max = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] > max) max = arr[i];
}
printf("%d", max);
Explanation: This code correctly initializes `max` to the first element and updates it by comparing with each element in the array.
#include <stdio.h>
int arr[4] = {1, 2, 3, 4};
int sum = 0;
for (int i = 0; i < 4; i++) {
sum += arr[i];
}
printf("%d", sum);
Correct Answer: 10
Explanation: The code calculates the sum of the array elements, resulting in `1 + 2 + 3 + 4 = 10`.
#include <stdio.h>
int arr[6] = {1, 2, 3, 4, 5, 6};
int x = 3;
int pos;
for (pos = 0; pos < 6; pos++) {
if (arr[pos] == x) break;
}
for (int i = pos; i < 5; i++) {
arr[i] = arr[i + 1];
}
Correct Answer: {1, 2, 4, 5, 6, 6}
Explanation: The code finds the first occurrence of `x` and shifts elements to the left, but duplicates the last element.
#include <stdio.h>
for (int i = 0; i < n / 2; i++) {
int temp = arr[i];
arr[i] = arr[n - i - 1];
arr[n - i - 1] = temp;
}
#include <stdio.h>
for (int i = 0; i < n; i++) {
int temp = arr[i];
arr[i] = arr[n - i - 1];
arr[n - i - 1] = temp;
}
#include <stdio.h>
for (int i = 0; i < n / 2; i++) {
int temp = arr[i];
arr[i] = arr[n - i];
arr[n - i] = temp;
}
#include <stdio.h>
for (int i = 0; i < n / 2; i++) {
int temp = arr[i];
arr[i] = arr[n - i - 2];
arr[n - i - 2] = temp;
}
Correct Answer:
#include <stdio.h>
for (int i = 0; i < n / 2; i++) {
int temp = arr[i];
arr[i] = arr[n - i - 1];
arr[n - i - 1] = temp;
}
Explanation: This code correctly swaps the elements from the beginning with the elements from the end up to the middle of the array.
Correct Answer: All of the above
Explanation: Array insertion can involve adding elements at the beginning, end, or any specific position in the array.
#include <stdio.h>
int arr[5] = {1, 2, 3, 4, 5};
for (int i = 0; i < 5; i++) {
if (arr[i] == 3) continue;
printf("%d ", arr[i]);
}
Correct Answer: 1 2 4 5
Explanation: The `continue` statement skips the printing of the element `3`.
#include <stdio.h>
int arr[10] = {0};
#include <stdio.h>
int arr[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Correct Answer: Both A and B
Explanation: Both methods correctly initialize all elements of the array to zero.
#include <stdio.h>
for (int i = 0; i < n - 1; i++) {
arr[i] = arr[i + 1];
}
#include <stdio.h>
for (int i = 0; i < n; i++) {
arr[i] = arr[i + 1];
}
#include <stdio.h>
for (int i = 1; i < n; i++) {
arr[i] = arr[i - 1];
}
#include <stdio.h>
for (int i = n - 1; i > 0; i--) {
arr[i] = arr[i - 1];
}
Correct Answer:
#include <stdio.h>
for (int i = 0; i < n - 1; i++) {
arr[i] = arr[i + 1];
}
Explanation: This code correctly shifts all elements one position to the left.
Correct Answer: By passing a pointer to the array
Explanation: In C, you pass an array to a function by passing a pointer to its first element.
#include <stdio.h>
void func(int arr[]);
#include <stdio.h>
void func(int arr[10]);
#include <stdio.h>
void func(int *arr);
Correct Answer: All of the above
Explanation: All these declarations are valid as they all indicate that the function takes a pointer to an integer.
#include <stdio.h>
printArray(arr, n);
#include <stdio.h>
printArray(arr);
#include <stdio.h>
printArray(&arr, n);
#include <stdio.h>
printArray(&arr);
Correct Answer:
#include <stdio.h>
printArray(arr, n);
Explanation: You call the function by passing the array and its size.
#include <stdio.h>
void modifyArray(int arr[], int n) {
for (int i = 0; i < n; i++) {
arr[i] += 1;
}
}
int main() {
int arr[3] = {1, 2, 3};
modifyArray(arr, 3);
for (int i = 0; i < 3; i++) {
printf("%d ", arr[i]);
}
return 0;
}
Correct Answer: 2 3 4
Explanation: The function `modifyArray` increments each element of the array by 1.
#include <stdio.h>
void printArray(int arr[], int n) {
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
}
int main() {
int arr[4] = {4, 3, 2, 1};
printArray(arr, 4);
return 0;
}
Correct Answer: 4 3 2 1
Explanation: The function `printArray` prints each element of the array as it is.
#include <stdio.h>
int sumArray(int arr[], int n);
#include <stdio.h>
void sumArray(int arr[], int n);
#include <stdio.h>
int sumArray(int *arr, int n);
Correct Answer: Both A and C
Explanation: Both declarations are correct since they both indicate a function that returns an integer and takes an array and its size as arguments.
#include <stdio.h>
int sumArray(int arr[], int n) {
int sum = 0;
for (int i = 0; i < n; i++) {
sum += arr[i];
}
return sum;
}
int main() {
int arr[4] = {1, 2, 3, 4};
printf("%d", sumArray(arr, 4));
return 0;
}
Correct Answer: 10
Explanation: The function `sumArray` calculates the sum of the array elements, which is `1 + 2 + 3 + 4 = 10`.
Correct Answer: Arrays are passed by reference to functions
Explanation: When an array is passed to a function, a pointer to the first element is passed, so the function can modify the original array.
Correct Answer: By specifying the dimensions in the function parameters
Explanation: You need to specify the second dimension when passing a two-dimensional array to a function.
#include <stdio.h>
void func(int arr[][]);
#include <stdio.h>
void func(int arr[10][]);
#include <stdio.h>
void func(int arr[][10]);
#include <stdio.h>
void func(int *arr[10]);
Correct Answer:
#include <stdio.h>
void func(int arr[][10]);
Explanation: You need to specify at least the second dimension when defining a function that takes a two-dimensional array.
#include <stdio.h>
void modifyArray(int arr[][3], int rows) {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < 3; j++) {
arr[i][j] += 1;
}
}
}
int main() {
int arr[2][3] = {{1, 2, 3}, {4, 5, 6}};
modifyArray(arr, 2);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
printf("%d ", arr[i][j]);
}
}
return 0;
}
Correct Answer: 2 3 4 5 6 7
Explanation: The function `modifyArray` increments each element of the two-dimensional array by 1.
#include <stdio.h>
void func(int *arr[]);
#include <stdio.h>
void func(int **arr);
#include <stdio.h>
void func(int arr[10]);
Correct Answer: Both A and B
Explanation: Both declarations indicate that the function takes an array of pointers to integers.
#include <stdio.h>
void modify(int arr[], int n);
#include <stdio.h>
void modify(int *arr, int n);
Correct Answer: Both A and B
Explanation: Both declarations are correct since they both indicate a function that takes a pointer to an array and its size as arguments.
#include <stdio.h>
void printEven(int arr[], int n) {
for (int i = 0; i < n; i++) {
if (arr[i] % 2 == 0) {
printf("%d ", arr[i]);
}
}
}
int main() {
int arr[5] = {1, 2, 3, 4, 5};
printEven(arr, 5);
return 0;
}
Correct Answer: 2 4
Explanation: The function `printEven` prints only the even elements of the array.
#include <stdio.h>
int maxElement(int arr[], int n);
#include <stdio.h>
void maxElement(int arr[], int n);
#include <stdio.h>
int maxElement(int *arr, int n);
Correct Answer: Both A and C
Explanation: Both declarations are correct since they both indicate a function that returns an integer and takes an array and its size as arguments.
#include <stdio.h>
int maxElement(int arr[], int n) {
int max = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
}
int main() {
int arr[5] = {5, 8, 3, 9, 2};
printf("%d", maxElement(arr, 5));
return 0;
}
Correct Answer: 9
Explanation: The function `maxElement` finds and returns the maximum element in the array, which is 9.
Correct Answer: Array size must be explicitly passed as a parameter to the function.
Explanation: When passing an array to a function, the size of the array must be explicitly passed as a parameter.
#include <stdio.h>
void doubleArray(int arr[], int n) {
for (int i = 0; i < n; i++) {
arr[i] *= 2;
}
}
int main() {
int arr[4] = {1, 2, 3, 4};
doubleArray(arr, 4);
for (int i = 0; i < 4; i++) {
printf("%d ", arr[i]);
}
return 0;
}
Correct Answer: 2 4 6 8
Explanation: The function `doubleArray` doubles each element of the array.
#include <stdio.h>
void func(char *arr);
#include <stdio.h>
void func(char arr[]);
#include <stdio.h>
void func(char arr[10]);
Correct Answer: All of the above
Explanation: All these declarations are valid and indicate a function that takes an array of characters as an argument.