Array in C MCQ
1. What is an array in C?
a) A data type
b) A collection of variables of different data types
c) A collection of variables of the same data type
d) A reserved keyword
Answer: c) A collection of variables of the same data type
2. What is the index of the first element in a C array?
a) 0
b) 1
c) -1
d) 10
Answer: a) 0
3. How do you declare an array of integers named myArray with 5 elements in C?
a) int myArray[5];
b) myArray[5] int;
c) array[5] int myArray;
d) int[] myArray = 5;
Answer: a) int myArray[5];
4. In C, can the size of an array be changed dynamically after its declaration?
a) Yes
b) No
Answer: b) No
5. Which of the following is true about C arrays?
a) Elements in an array can have different data types.
b) The size of an array must be known at compile-time.
c) Arrays in C can automatically resize themselves.
d) Arrays can have variable names like "array1," "array2," etc.
Answer: b) The size of an array must be known at compile-time.
6. What is the size of the array in the following declaration: char name[50];?
a) 50
b) 49
Answer: a) 50
7. To access the last element of an array arr of size n, what index should be used?
a) n
b) n - 1
c) n + 1
d) 1
Answer: b) n - 1
8. Which operator is used to access elements of an array in C?
a) . (dot)
b) -> (arrow)
c) [] (subscript)
d) () (parentheses)
Answer: c) [] (subscript)
9. How can you initialize an array in C at the time of declaration?
a) int myArray[] = {1, 2, 3};
b) int myArray[3] = {1, 2, 3};
c) myArray[1, 2, 3];
d) int[] myArray = {1, 2, 3};
Answer: a) int myArray[] = {1, 2, 3};
10. What is the maximum number of elements an array can hold in C?
a) Limited by memory
b) 256
c) 65535
d) 1024
Answer: a) Limited by memory
11. What will be the output of the following code snippet?c
int arr[5] = {1, 2, 3, 4, 5};
printf("%d", arr[3]);
a) 1
b) 2
c) 3
d) 4
Answer: d) 4
12. Which library should be included to use the sizeof operator in C?
a) <stdio.h>
b) <stdlib.h>
c) <string.h>
d) <stddef.h>
Answer: d) <stddef.h>
13. What is the purpose of the sizeof operator in C?
a) To determine the number of elements in an array
b) To allocate memory for an array
c) To determine the size in bytes of a data type or object
d) To declare the size of an array
Answer: c) To determine the size in bytes of a data type or object
14. How do you find the length of an array in C?
a) Using the len function
b) By subtracting the first element's index from the last
c) Using the sizeof operator and dividing by the size of one element
d) By counting the number of elements in a loop
Answer: c) Using the sizeof operator and dividing by the size of one element
15. What is the purpose of the sizeof operator in the context of arrays?
a) To determine the number of elements in the array
b) To allocate memory for the array
c) To calculate the sum of all elements in the array
d) To determine the size of the entire array in bytes
Answer: d) To determine the size of the entire array in bytes
16. Which of the following is the correct way to pass an array to a function in C?
a) int myFunction(int arr[])
b) int myFunction(int *arr, int size)
c) int myFunction(int &arr, int size)
d) int myFunction(int arr[10])
Answer: b) int myFunction(int *arr, int size)
17. What is a "two-dimensional array" in C?
a) An array with two elements
b) An array that is allocated on the heap
c) An array of arrays
d) An array that stores characters
Answer: c) An array of arrays
18. How is a two-dimensional array typically declared in C?
a) int arr[2];
b) int arr[2, 2];
c) int arr[2][2];
d) int[2][2] arr;
Answer: c) int arr[2][2];
19. What is the purpose of the comma in a two-dimensional array declaration like int arr[2][2]?
a) It separates individual elements in the array.
b) It specifies the number of rows and columns.
c) It is a syntax error; there should be no comma.
d) It indicates the data type of the array.
Answer: b) It specifies the number of rows and columns.
20. What is the maximum number of indices required to access an element in a three-dimensional array in C?
a) 1
b) 2
c) 3
d) 4
Answer: c) 3
21. In C, how do you pass a two-dimensional array to a function?
a) As a pointer to the first element
b) As an array with two dimensions
c) As an array of pointers
d) As a two-dimensional pointer
Answer: a) As a pointer to the first element
22. What is the relationship between a pointer and an array in C?
a) Pointers and arrays are completely unrelated in C.
b) A pointer can point to the first element of an array.
c) An array can store multiple pointers.
d) A pointer is another name for an array.
Answer: b) A pointer can point to the first element of an array.
23. Which function can be used to sort an array in C?
a) sortArray()
b) bubbleSort()
c) quickSort()
d) qsort()
Answer: d) qsort()
24. What does the qsort() function require as an argument to compare elements during sorting?
a) A comparison function
b) The size of the array
c) A random number generator
d) The maximum value in the array
Answer: a) A comparison function
25. Which of the following statements is true about returning an entire array from a function in C?
a) C allows returning an entire array from a function.
b) You can return an array, but only if it's a global variable.
c) You can return an array, but only if it's a dynamically allocated array.
d) C does not allow returning an entire array; you can return a pointer to an array instead.
Answer: d) C does not allow returning an entire array; you can return a pointer to an array instead.
0 Comments