Arrays in C

This quiz contains question from various concepts related to arrays in C which are perfect to test your understanding of the topic.

Last Updated :
Discuss
Comments

Question 1

Which of the following correctly declares an array of 10 integers in C?

  • int arr(10);

  • int arr[10];

  • array int arr[10];

  • int[10] arr;

Question 2

Which of the following statements about arrays is TRUE in C?

  • Arrays can hold different data types.

  • The size of an array can be changed during execution.

  • An array stores elements of the same type in contiguous memory.

  • Arrays are not supported in C.

Question 3

What is the index of the first element in a C array?

  • 0

  • 1

  • -1

  • Depends on Array.

Question 4

What is the correct way to initialize all elements of an array to zero in C?

  • int arr[5] = (0);


  • int arr[5] = {0};


  • int arr[5] = 0;

  • int arr[5] = [0];

Question 5

Which of the following is NOT a valid array declaration?

  • int arr[10];

  • int arr[] = {1, 2, 3};

  • int arr[3] = {1, 2, 3, 4};

  • float marks[5];

Question 6

What is the value of arr[1] after the following declaration?

C
int arr[3] = {10}; 


  • 0

  • 10

  • Garbage Value

  • Compilation Error.

Question 7

What is true about partially initialized arrays in C?


  • All elements must be initialized

  • Uninitialized elements get garbage values

  • Remaining elements are initialized to zero

  • Compiler throws error

Question 8

Which of the following allows you to iterate over a C array using a pointer?

  • for (int *p = arr; p <= arr + size; p++)

  • for (int *p = arr; p < arr + size; p++)

  • for (int p = arr; p < arr + size; p++)

  • for (int p = &arr; p <= arr + size; p++)

Question 9

What is the difference between int arr[5]; and int *arr = malloc(5 * sizeof(int));?

  • No Difference

  • The first is static, the second is dynamic

  • The second doesn't allocate memory

  • Both use stack memory

Question 10

What happens if you use sizeof on a pointer to an array?

  • Gives total array size

  • Gives size of first element

  • Gives error

  • Gives size of pointer

Tags:

There are 19 questions to complete.

Take a part in the ongoing discussion