Arrays Interview Questions

    Question 1Array Declaration

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

    Question 2Array Indexing

    If int arr[5]; is declared, what are the valid indices?

    Question 3Array Initialization

    Which of the following correctly initializes an array in C?

    Question 4Accessing Array Elements

    What will the following code print?

    #include <stdio.h> int main() { int arr[3] = {10, 20, 30}; printf("%d", arr[1]); return 0; }

    Question 5Array and Loop

    What will be printed?

    #include <stdio.h> int main() { int arr[4] = {2, 4, 6, 8}; for (int i = 0; i < 4; i++) { printf("%d ", arr[i]); } return 0; }

    Question 6Array Out of Bounds

    What happens if we try to access arr[10] when arr has size 5?

    Question 72D Array Size

    How many elements does an array int arr[3][4]; contain?

    Question 82D Array Access

    What will be printed?

    #include <stdio.h> int main() { int arr[2][2] = {{1, 2}, {3, 4}}; printf("%d", arr[1][0]); return 0; }

    Question 9Strings as Arrays

    Which of the following is the correct declaration of a string in C?

    Question 10Sizeof Operator

    If int arr[10]; and sizeof(int) = 4, what will sizeof(arr) return?