Arrays Interview Questions

    Question 1C++ Array Declaration

    Which of the following is the correct way to declare an integer array of size 5 in C++?

    Question 2C++ Guess the Output – Array Initialization

    What will be the output of the following code?

    #include <iostream> using namespace std; int main() { int arr[5] = {1, 2, 3}; cout << arr[3]; return 0; }

    Question 3C++ Array Index

    What will happen if you try to access arr[10] in an array declared as int arr[5];?

    Question 4C++ Guess the Output – Array Elements

    What will be the output of the following code?

    #include <iostream> using namespace std; int main() { int arr[] = {10, 20, 30, 40}; cout << arr[1] + arr[3]; return 0; }

    Question 5C++ Size of Array

    If we declare int arr[10]; then what is sizeof(arr) (assuming int takes 4 bytes)?

    Question 6C++ Guess the Output – Array Traversal

    What will be the output of the following code?

    #include <iostream> using namespace std; int main() { int arr[3] = {1, 2, 3}; for(int i = 0; i < 3; i++) { cout << arr[i] << " "; } return 0; }

    Question 7C++ Multidimensional Array

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

    Question 8C++ Guess the Output – Multidimensional Array

    What will be the output of the following code?

    #include <iostream> using namespace std; int main() { int arr[2][2] = { {1, 2}, {3, 4} }; cout << arr[1][0]; return 0; }

    Question 9C++ Array and Functions

    When an array is passed to a function in C++, what is actually passed?

    Question 10C++ Guess the Output – Array and Pointers

    What will the following code print?

    #include <iostream> using namespace std; int main() { int arr[] = {5, 10, 15}; cout << *arr; return 0; }