# One-dimensional arrays MCQs

What is the correct way to declare a one-dimensional array of integers in C?

a) int array[10];
b) int array;
c) array int[10];
d) int[10] array;
Which of the following correctly initializes an array of size 5 with all zeros in C++?

a) int array[5] = {0};
b) int array = {0, 0, 0, 0, 0};
c) int array[5] = {0, 0, 0, 0, 0};
d) int array[5] = {0, 0, 0, 0};
Answer: a) int array[5] = {0};
What is the index of the last element in an array of size n?

a) n
b) n-1
c) n+1
d) 0
What is the time complexity of accessing an element in a one-dimensional array by its index?

a) O(n)
b) O(log n)
c) O(1)
d) O(n^2)
What is the value of the first element in an array initialized as int array[3] = {1, 2, 3};?

a) 0
b) 1
c) 2
d) 3
How do you pass a one-dimensional array to a function in C?

a) void function(int array[10]);
b) void function(int array[]);
c) void function(int *array);
d) All of the above
Answer: d) All of the above
What is the output of the following code? int array[5] = {1, 2, 3, 4, 5}; printf(“%d”, array[2]);

a) 1
b) 2
c) 3
d) 4
Which of the following statements about one-dimensional arrays is false?

a) Arrays can store multiple values of the same type.
b) Array elements are stored in contiguous memory locations.
c) The size of an array must be a constant expression in C.
d) The size of an array can be changed after declaration.
Answer: d) The size of an array can be changed after declaration.
How can you find the number of elements in an array int array[10]; in C?

a) sizeof(array) / sizeof(array[0])
b) sizeof(array) / sizeof(int)
c) sizeof(array[0]) / sizeof(array)
d) sizeof(int) / sizeof(array)
What is the initial value of an uninitialized array in C?

a) 0
b) Random garbage values
c) -1
d) Null
Which of the following correctly accesses the third element of an array named data?

a) data[3]
b) data[2]
c) data[1]
d) data[0]
Which operation is not typically performed directly on one-dimensional arrays?

a) Insertion
b) Deletion
c) Traversal
d) Random Access
In which of the following scenarios is a one-dimensional array preferred over other data structures?

a) When you need dynamic resizing
c) When you need to store key-value pairs
d) When you need a Last-In-First-Out (LIFO) data structure
What is the result of the following code? int array[4] = {1, 2}; printf(“%d”, array[3]);

a) 0
b) 1
c) 2
d) Undefined behavior
How do you correctly assign the value 10 to the first element of an array arr in Java?

a) arr = 10;
b) arr[0] = 10;
c) arr[1] = 10;
d) arr[] = 10;
Which of the following statements about arrays in Java is true?

a) Arrays can have elements of different types.
b) The length of an array can be changed after it is created.
c) The size of an array must be specified when it is created.
d) Arrays are passed by value to methods.
Answer: c) The size of an array must be specified when it is created.
What is the output of the following code in Python? arr = [1, 2, 3, 4, 5]; print(arr[-1])

a) 1
b) 2
c) 4
d) 5
Which function would you use to find the length of an array arr in Python?

a) size(arr)
b) len(arr)
c) length(arr)
d) count(arr)
How do you declare an array of 10 integers in JavaScript?

a) var array = new Array(10);
b) var array = [10];
c) int array[10];
d) array = (10);
Answer: a) var array = new Array(10);
What is the output of the following code? int array[5] = {1, 2, 3, 4, 5}; printf(“%d”, array[5]);

a) 1
b) 5
c) 0
d) Undefined behavior