### C Array MCQ

Arrays are fundamental to programming, and in C, they allow us to store multiple values of the same data type in a single data structure. Ready to assess your understanding of C arrays? Let's jump into this multiple-choice quiz.

Each question is followed by the correct answer and an explanation to help reinforce your knowledge.

## 1. How is an array with 5 integers declared in C?

A) int a(5);
B) int a;
C) int a;
D) array a;

B) int a;

### Explanation:

Arrays in C are declared with the datatype followed by the array name and its size in square brackets.

## 2. What is the index of the first element in an array?

A) 0
B) 1
C) First
D) Start

A) 0

### Explanation:

Array indexing in C starts from 0, so the first element's index is 0.

## 3. To access the third element of an array named 'arr', you would use:

A) arr
B) arr
C) arr(2)
D) arr(3)

A) arr

### Explanation:

As indexing starts from 0, the third element is accessed using index 2.

## 4. What will be the size in bytes of an array int arr; if an integer requires 4 bytes of memory?

A) 40
B) 80
C) 20
D) 5

B) 80

### Explanation:

For 20 integers each of 4 bytes, the array will be 20 * 4 = 80 bytes.

## 5. Which of the following is a valid declaration for a 2D array?

A) int a[][] = {{1,2}, {3,4}};
B) int a[2,2] = {{1,2}, {3,4}};
C) int a = {{1,2}, {3,4}};
D) array a = {{1,2}, {3,4}};

C) int a = {{1,2}, {3,4}};

### Explanation:

In C, multi-dimensional arrays are declared by specifying each dimension's size inside its respective brackets.

## 6. Which of the following is the correct way to declare a 3D array?

A) int a[][][] = {{{1},{2},{3}},{{4},{5},{6}}};
B) int a;
C) int a;
D) Both A and B

D) Both A and B

### Explanation:

Both declarations are valid ways to declare a 3D array.

## 7. In an array declaration int arr = {1, 2, 3};, what will be the value of arr?

A) 1
B) 2
C) 3
D) 0

D) 0

### Explanation:

Elements that aren't explicitly initialized are automatically initialized to 0.

## 8. Which function is used to determine the length of an array?

A) sizeof()
B) length()
C) len()
D) size()

A) sizeof()

### Explanation:

The sizeof() function can be used to determine the memory size occupied by the array. To get the number of elements, you'd divide the size of the entire array by the size of a single element.

## 9. Which statement about arrays in C is false?

a) Arrays can store multiple values of different data types.
b) The size of an array must be specified at the time of declaration.
c) The elements of an array are stored in contiguous memory locations.
d) The array index starts from 0.

a) Arrays can store multiple values of different data types.

### Explanation:

Arrays in C store multiple values of the same data type.

## 10. Which of the following correctly initializes an array of size 5 with all values set to 0?

A) int arr = {0};
B) int arr;
C) int arr = {};
D) int arr[] = {0,0,0,0,0};

A) int arr = {0};

### Explanation:

When an array is initialized with fewer values than its declared size, the remaining elements get automatically initialized to 0.

## 11. How would you declare a two-dimensional integer array of 3 rows and 4 columns?

a) int arr[3, 4];
b) int arr;
c) int arr;
d) int arr[ ][ ] = {3, 4};

b) int arr;

### Explanation:

A two-dimensional array in C is declared using the type name[row_size][column_size].

## 12. What will the value of arr be in the following code segment?

``int arr[] = {10, 20, 30, 40, 50};``
a) 10
b) 20
c) 30
d) 40