Site icon T4Tutorials.com

Arrays MCQs Questions Answers – C++

1. Which of the following statements is true about multidimensional arrays in C++?

(A) They can only be 2D arrays


(B) The size of each dimension must be known at compile time


(C) They can store elements of different types


(D) They are always dynamically allocated



2. How do you declare a 2D array of 3 rows and 4 columns in C++?

(A) int arr[3][4];


(B) int arr(3,4);


(C) int arr[4][3];


(D) int arr{3,4};



3. What is the output of the following code? int arr[3] = {5}; cout << arr[1];

(A) 0


(B) 5


(C) Garbage value


(D) Compilation error



4. Which of the following correctly accesses the last element of an array int arr[10]; ?

(A) arr[0]


(B) arr[10]


(C) arr[last]


(D) arr[9]



5. Which operator is used to get the address of the first element of an array?

(A) *


(B) &


(C) >


(D) %



6. What happens if you partially initialize an array int arr[5] = {1, 2}; ?

(A) Compiler error occurs


(B) Remaining elements are set to zero


(C) Remaining elements are garbage values


(D) Array size reduces to 2



7. Which of the following is a valid way to pass an array to a function in C++?

(A) void func(int arr[])


(B) void func(int arr[5])


(C) void func(int *arr)


(D) All of the above



8. What is the output of the code? int arr[] = {1,2,3}; cout << sizeof(arr);

(A) Size of array in bytes


(B) 3


(C) 0


(D) Compilation error



9. Can an array in C++ be initialized with a for loop during declaration?

(A) Yes


(B) Only for global arrays


(C) No


(D) Only for character arrays



10. Which of the following is true about array names in C++?

(A) Array name is a pointer to the first element


(B) Array name can be assigned to another pointer


(C) Array name can be incremented


(D) Array name stores the array size



11. How do you declare a constant array whose elements cannot be modified?

(A) const int arr[5];


(B) int const arr[5];


(C) Both (A) and (B)


(D) int arr[5] const;



12. Identify the error in the following code snippet:
int arr[5];
arr[5] = 10;
int a b

(A) Array index out of bounds


(B) Syntax error in declaration


(C) Cannot assign value to array element


(D) No error, code works fine



More Array MCQs

 

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

 

 

Programming C Plus Plus MCQs Homepage

Low-level and high-level languages MCQs

Procedural and non Procedural languages MCQs

C++ STANDARD LIBRARY MCQs

 Array  MCQs 

Arrays MCQs 2

Pointers Solved MCQs

Inline Function MCQs – C++

Top 50 Programming  C++ MCQs 

MCQs of introduction to programming

Past Papers 2022 C++ MCQs

Past Papers 2021 C++ MCQs

Past Papers 2020 C++ MCQs

Past Papers 2019 C++ MCQs

Highly Recommended C++  Important MCQs with Explanation

OOP

OOP intro & examples MCQs

Classes and Inheritance MCQs

Friend Function MCQs

Virtual Function MCQs

Polymorphism MCQs

Polymorphism MCQs 2

Exit mobile version