One-dimensional arrays MCQs

By: Prof. Dr. Fazal Rehman Shamil | Last updated: September 20, 2024

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;
Answer: a) int array[10];
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
Answer: b) n-1
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)
Answer: c) O(1)
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
Answer: b) 1
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
Answer: c) 3
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)
Answer: a) sizeof(array) / sizeof(array[0])
What is the initial value of an uninitialized array in C?

a) 0
b) Random garbage values
c) -1
d) Null
Answer: b) Random garbage values
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]
Answer: b) data[2]
Which operation is not typically performed directly on one-dimensional arrays?

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

a) When you need dynamic resizing
b) When you need fast random access to elements
c) When you need to store key-value pairs
d) When you need a Last-In-First-Out (LIFO) data structure
Answer: b) When you need fast random access to elements
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
Answer: a) 0
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;
Answer: b) arr[0] = 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
Answer: 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)
Answer: b) len(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
Answer: d) Undefined behavior

 

Data Structures MCQs

Basic Concepts

  1. Introduction to Data Structures
  2. Complexity Analysis MCQs

Linear Data Structures MCQs

  1. Arrays MCQs
  2. Linked Lists MCQs
  3. Stacks MCQs
  4. Queues MCQs

Non-Linear Data Structures MCQs

  1. Trees MCQs
  2. Heaps MCQs
  3. Graphs MCQs

Hashing MCQs MCQs

  1. Hash Tables

Sorting and Searching Algorithms MCQs 

  1. Sorting Algorithms MCQs
  2. Searching Algorithms MCQs

Miscellaneous

  1. Memory Management in data structures MCQs
  2. String Manipulation Algorithms MCQs
  1. Data Structures MCQs 1
  2. Data Structures MCQs 2
  3. Data Structures MCQs 3
  4. Data Structures MCQs 4
  5. Data Structures MCQs 5
  6. Stacks Solved MCQs
  7. Queues MCQs
  8. pointer mcqs
  9. Array MCQs