4.1 - Arrays.


Back Button Home

4.1.1 - Introduction to Array and its Types.


1. What is the primary purpose of an array in programming?
  • (A) Store a single value
  • (B) Store multiple values within a single variable
  • (C) Increase performance
  • (D) Create functions
Correct Answer: (B) Store multiple values within a single variable
2. What is the starting index for an array in C?
  • (A) 1
  • (B) 0
  • (C) -1
  • (D) Depends on the array size
Correct Answer: (B) 0
3. How can an array be declared in C?
  • (A) int array[];
  • (B) array int[5];
  • (C) int array(5);
  • (D) All of the above
Correct Answer: (A) int array[];
4. What type of values can arrays hold?
  • (A) Only integers
  • (B) Only characters
  • (C) Any data type
  • (D) Only floating-point numbers
Correct Answer: (C) Any data type
5. Which of the following is NOT an operation that can be performed on an array?
  • (A) Traversal
  • (B) Inheritance
  • (C) Insertion
  • (D) Deletion
Correct Answer: (B) Inheritance
6. How do you access the first element of an array named "arr"?
  • (A) arr[1]
  • (B) arr[0]
  • (C) arr[-1]
  • (D) arr[first]
Correct Answer: (B) arr[0]
7. What will be the output of the following code snippet?
int arr[3] = {1, 2, 3}; printf("%d", arr[3]);
  • (A) 0
  • (B) 1
  • (C) Compilation error
  • (D) Random value
Correct Answer: (C) Compilation error
8. In the declaration int arr[5] = {1, 2, 3}; what happens to the remaining two elements?
  • (A) They are set to 0
  • (B) They are left uninitialized
  • (C) They are set to random values
  • (D) Compilation error
Correct Answer: (A) They are set to 0
9. Which of the following statements is true about arrays in C?
  • (A) Arrays can hold different types of elements
  • (B) The size of an array can change during runtime
  • (C) Arrays have a fixed size once declared
  • (D) Arrays are always initialized to 1
Correct Answer: (C) Arrays have a fixed size once declared
10. What does the process of array subscripting involve?
  • (A) Declaring an array
  • (B) Accessing specific elements using their index
  • (C) Initializing an array
  • (D) Sorting an array
Correct Answer: (B) Accessing specific elements using their index
11. What is the time complexity for retrieving any array element?
  • (A) O(n)
  • (B) O(log n)
  • (C) O(1)
  • (D) O(n²)
Correct Answer: (C) O(1)
12. How many dimensions can an array have in C?
  • (A) 1
  • (B) 2
  • (C) Unlimited
  • (D) Only 3
Correct Answer: (C) Unlimited
13. What is the syntax to declare a one-dimensional array of integers?
  • (A) int array[];
  • (B) int array[10];
  • (C) Both a and b
  • (D) int array();
Correct Answer: (C) Both a and b
14. Which of the following is a disadvantage of using arrays?
  • (A) They can hold multiple types
  • (B) They are dynamically allocated
  • (C) Their size cannot be changed after initialization
  • (D) They are always initialized to zero
Correct Answer: (C) Their size cannot be changed after initialization
15. How can an array be initialized with a loop?
  • (A) By using a while loop only
  • (B) By using a for loop
  • (C) By directly assigning values
  • (D) Arrays cannot be initialized with loops
Correct Answer: (B) By using a for loop
16. In the array declaration int arr[10]; how many elements can it hold?
  • (A) 5
  • (B) 10
  • (C) 11
  • (D) 0
Correct Answer: (B) 10
17. What is the output of the following code?
int arr[5] = {0, 1, 2, 3, 4}; printf("%d", arr[2]);
  • (A) 0
  • (B) 1
  • (C) 2
  • (D) 3
Correct Answer: (C) 2
18. Which operation is used to combine two different arrays?
  • (A) Merging
  • (B) Sorting
  • (C) Traversal
  • (D) Searching
Correct Answer: (A) Merging
19. What is the purpose of the loop in the following code?
for (i = 0; i < 5; i++) { arr[i] = i + 1; }
  • (A) To read values from the user
  • (B) To initialize the array elements
  • (C) To print the array
  • (D) To sort the array
Correct Answer: (B) To initialize the array elements
20. What will be the output of the following code?
int arr[5] = {1, 2, 3, 4, 5}; arr[2] = 10;
                     printf("%d", arr[2]);
  • (A) 3
  • (B) 2
  • (C) 10
  • (D) 1
Correct Answer: (C) 10
21. How are multidimensional arrays stored in memory?
  • (A) Row-major order
  • (B) Column-major order
  • (C) Random order
  • (D) They cannot be stored in memory
Correct Answer: (A) Row-major order
22. What is a 2-dimensional array commonly referred to as?
  • (A) Array of objects
  • (B) Array of arrays
  • (C) List of lists
  • (D) Group of variables
Correct Answer: (B) Array of arrays
23. Which of the following is a valid 2-dimensional array declaration?
  • (A) int array[][] = {1, 2, 3, 4, 5, 6}
  • (B) int array[3][] = {1, 2, 3, 4, 5, 6}
  • (C) int array[3][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9}
  • (D) None of the above
Correct Answer: (C) int array[3][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
24. In C, how are elements in 2D arrays inserted?
  • (A) Through loops
  • (B) Direct assignment
  • (C) Dynamic allocation
  • (D) Using pointers
Correct Answer: (A) Through loops
25. Which function is used to read elements into a 2D array?
  • (A) printf
  • (B) scanf
  • (C) fgets
  • (D) malloc
Correct Answer: (B) scanf
26. How can an element in a 2D array be updated?
  • (A) By swapping rows
  • (B) By modifying the required index position
  • (C) By using pointer arithmetic
  • (D) By re-declaring the array
Correct Answer: (B) By modifying the required index position
27. How is the row number of an element in a 2D array removed?
  • (A) Through reinitializing the array
  • (B) Using loops to overwrite the elements
  • (C) Using the free() function
  • (D) By clearing memory space directly
Correct Answer: (B) Using loops to overwrite the elements
28. What is the result of multiplying two matrices?
  • (A) Addition of corresponding elements
  • (B) Sum of row and column elements
  • (C) Matrix multiplication results in a new matrix
  • (D) Cannot multiply matrices
Correct Answer: (C) Matrix multiplication results in a new matrix
29. How is matrix multiplication performed?
  • (A) By multiplying each row of the first matrix with each row of the second
  • (B) By multiplying each row of the first matrix with each column of the second matrix
  • (C) By adding corresponding elements
  • (D) By multiplying only diagonal elements
Correct Answer: (B) By multiplying each row of the first matrix with each column of the second matrix
30. How are rows and columns specified for a 2D array in C?
  • (A) During the declaration only
  • (B) Through the initialization only
  • (C) Can be omitted for rows, but columns must be specified
  • (D) Both can be omitted
Correct Answer: (C) Can be omitted for rows, but columns must be specified
31. What is the syntax to declare a 2D array in C?
  • (A) data_type array_name[rows, columns];
  • (B) data_type array_name[rows][columns];
  • (C) data_type array_name[rows|columns];
  • (D) None of the above
Correct Answer: (B) data_type array_name[rows][columns];
32. What is the dimension of an array defined as int arr[4][3]?
  • (A) 12 elements
  • (B) 4 elements
  • (C) 3 elements
  • (D) 7 elements
Correct Answer: (A) 12 elements
33. Which one of the following is a correct syntax for declaring a 2D array?
  • (A) int arr[2][3] = {{1, 2}, {3, 4}, {5, 6}};
  • (B) int arr[2,3] = {{1, 2}, {3, 4}, {5, 6}};
  • (C) int arr[2][3] = {1, 2, 3, 4, 5, 6};
  • (D) int arr = {1, 2, 3, 4, 5, 6};
Correct Answer: (C) int arr[2][3] = {1, 2, 3, 4, 5, 6};
34. What will be the result of int arr[2][3] = {1, 2, 3, 4, 5, 6};?
  • (A) Error
  • (B) Array with 6 elements
  • (C) 2 rows and 3 columns matrix
  • (D) None of the above
Correct Answer: (C) 2 rows and 3 columns matrix
35. What is a matrix in a 2D array referred to when rows and columns are equal?
  • (A) Rectangle matrix
  • (B) Diagonal matrix
  • (C) Square matrix
  • (D) Equal matrix
Correct Answer: (C) Square matrix
36. How does matrix multiplication handle elements of the resulting matrix?
  • (A) By multiplying corresponding elements
  • (B) By multiplying rows of the first matrix with rows of the second
  • (C) By summing the products of the respective row and column elements
  • (D) None of the above
Correct Answer: (C) By summing the products of the respective row and column elements
37. What does the second index of a 2D array represent?
  • (A) The column number
  • (B) The row number
  • (C) The value of the element
  • (D) None of the above
Correct Answer: (A) The column number
38. When dynamically allocating a 2D array, what does malloc() return?
  • (A) Pointer to the first element
  • (B) Null pointer
  • (C) Address of the last element
  • (D) None of the above
Correct Answer: (A) Pointer to the first element
39. What is the output of the following code:
int arr[2][2] = {{1, 2}, {3, 4}}; printf("%d", arr[1][1]);
?
  • (A) 1
  • (B) 2
  • (C) 3
  • (D) 4
Correct Answer: (D) 4
40. What is the correct way to access the first row and second column of a 2D array named 'matrix'?
  • (A) matrix[0, 1]
  • (B) matrix[1][0]
  • (C) matrix[0][1]
  • (D) matrix[1][1]
Correct Answer: (C) matrix[0][1]