Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Array Quiz

Total questions: 47

Worksheet time: 24mins

Name
Class
Date
1.

Choose the correct way to declare an array in C.

a)

array{10};

b)

int array[10];

c)

int array;

d)

int array(10);

e)

array int[10];

2.

What will be the output of the following code? int arr[] = {1, 2, 3}; printf("%d", arr[1]);

a)

1

b)

2

c)

3

d)

Garbage value

e)

Compilation error

3.

What is the index of the last element in an array declared as int a[5];?

a)

0

b)

4

c)

5

d)

6

e)

Depends on compiler

4.

Which of the following accesses the third element in an array a?

a)

a(3)

b)

a.3

c)

a[3]

d)

a[2]

e)

a->3

5.

Which loop is best suited to access array elements sequentially?

a)

if loop

b)

for loop

c)

goto

d)

switch

e)

continue

6.

What will be the output of the following code? int a[3] = {10, 20, 30}; printf("%d", *(a + 1));

a)

10

b)

20

c)

30

d)

Address of a

e)

Compilation error

7.

What does sizeof(arr) return for int arr[5] = {1, 2, 3, 4, 5};?

a)

5

b)

10

c)

20

d)

4

e)

Depends on system

8.

Which of the following is not a valid array declaration?

a)

int arr[10];

b)

float marks[5];

c)

char name[] = "John";

d)

double data[3.5];

e)

int matrix[2][2];

9.

What is the result of this expression: arr[3] = *(arr + 3);?

a)

Invalid syntax

b)

Assigns a value

c)

Causes segmentation fault

d)

Returns array size

e)

Swaps elements

10.

How many elements are stored in int a[] = {1, 2, 3, 4};?

a)

3

b)

4

c)

5

d)

Cannot determine

e)

0

11.

Which operator is used to access elements in an array?

a)

()

b)

[]

c)

{}

d)

->

e)

::

12.

What will be printed by the code below? int a[5] = {0}; printf("%d", a[4]);

a)

0

b)

4

c)

Garbage value

d)

Compilation error

e)

Runtime error

13.

What will be the output of this code? int a[] = {10, 20, 30}; printf("%d", a[3]);

a)

10

b)

20

c)

30

d)

Garbage value

e)

Compilation error

14.

Arrays in C are:

a)

Dynamically typed

b)

Heterogeneous

c)

Zero-indexed

d)

One-indexed

e)

Flexible in size

15.

What is the size of int arr[10]; if int is 4 bytes?

a)

10

b)

20

c)

40

d)

50

e)

100

16.

Identify the correct syntax to input values into an array using a loop.

a)

scanf("%d", arr[i]);

b)

scanf("%d", &arr[i]);

c)

cin >> arr[i];

d)

input(arr[i]);

e)

get(arr[i]);

17.

Which header file is required for printf and scanf?

a)

stdlib.h

b)

string.h

c)

stdio.h

d)

conio.h

e)

array.h

18.

Which of these best describes an array in C?

a)

Pointer

b)

Structure

c)

Class

d)

File

e)

None of the above

19.

What will be the output? int a[3] = {1, 2, 3}; printf("%d", a[1] + a[2]);

a)

3

b)

5

c)

6

d)

2

e)

4

20.

Which statement is true about array indexing in C?

a)

It starts at 1

b)

It starts at 0

c)

It starts at -1

d)

It starts at 2

e)

It's user-defined

21.

Which expression refers to the first element of array a?

a)

a[0]

b)

*a

c)

*(a + 0)

d)

All of the above

e)

a(0)

22.

What happens if you access out-of-bound index in an array?

a)

Returns 0

b)

Returns NULL

c)

Undefined behavior

d)

Compilation error

e)

Assigns 0

23.

What is the default value of a static int array?

a)

0

b)

1

c)

Garbage value

d)

NULL

e)

Undefined

24.

Which of these correctly initializes all elements to 0?

a)

int a[5] = {0};

b)

int a[5];

c)

int a[] = {1,2,3};

d)

int a = {0};

e)

int a[5] = {1};

25.

What does *(arr + i) do?

a)

Assigns a pointer

b)

Refers to ith element

c)

Declares array

d)

Deletes array

e)

Allocates memory

26.

Array names in C act as:

a)

Integers

b)

Functions

c)

Constants

d)

Pointers

e)

Classes

27.

What will this print? int a[2][2] = {{1, 2}, {3, 4}}; printf("%d", a[1][0]);

a)

1

b)

2

c)

3

d)

4

e)

Compilation error

28.

What is the output? int a[5]; a[0] = 1; a[4] = 5; printf("%d", a[2]);

a)

1

b)

2

c)

5

d)

Garbage value

e)

0

29.

Which of the following correctly declares a 2D array?

a)

int a(3,3);

b)

int a{3}{3};

c)

int a[3][3];

d)

array int[3][3];

e)

int a<3,3>;

30.

What is the output? int a[] = {10, 20, 30, 40}; printf("%d", sizeof(a)/sizeof(a[0]));

a)

2

b)

3

c)

4

d)

5

e)

Compilation error

31.

Which access is correct in 2D array int a[2][3];?

a)

a[2][3]

b)

a[1][2]

c)

a[3][2]

d)

a(1,2)

e)

a{1}{2}

32.

What will be the output? int arr[3] = {5}; printf("%d", arr[2]);

a)

0

b)

5

c)

3

d)

Garbage

e)

Compilation error

33.

In C, which array declaration is invalid?

a)

int a[3] = {1, 2};

b)

int a[] = {1, 2, 3};

c)

int a[2] = {1, 2, 3};

d)

int a[3];

e)

int a[0];

34.

What happens when you assign a = &arr[0];?

a)

Error

b)

Assigns pointer

c)

Allocates memory

d)

Deletes value

e)

Overwrites array

35.

int *ptr = arr; means:

a)

ptr is an array

b)

ptr is a constant

c)

ptr points to first element

d)

ptr holds garbage

e)

Compilation fails

36.

Which of the following is correct?

a)

*(arr + i) = arr[i]

b)

arr[i] = i[arr]

c)

Both a and b

d)

Only b

e)

Only a

37.

The time complexity for accessing an array element is:

a)

O(n)

b)

O(log n)

c)

O(1)

d)

O(n log n)

e)

O(n²)

38.

Can array size be changed after declaration?

a)

Yes

b)

No

c)

Only with malloc

d)

Only with realloc

e)

Only in Java

39.

Array elements are stored in:

a)

Heap

b)

Stack

c)

Queue

d)

Hash

e)

Tree

40.

To pass an array to a function, use:

a)

Pointers

b)

Structures

c)

Arrays can’t be passed

d)

Classes

e)

Files

41.

Arrays in C are:

a)

Objects

b)

Functions

c)

Homogeneous

d)

Heterogeneous

e)

None of these

42.

Which one is a correct multidimensional array initialization?

a)

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

b)

int a = [2][2];

c)

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

d)

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

e)

array int[2][2];

43.

What does int a[3] = {1}; initialize?

a)

a[0]=1, a[1]=1, a[2]=1

b)

All to 0

c)

a[0]=1, a[1]=0, a[2]=0

d)

Only a[0]=1

e)

Compilation error

44.

If int a[5] = {1, 2, 3, 4, 5};, then *(a + 4) is:

a)

1

b)

2

c)

3

d)

4

e)

5

45.

Arrays in C are passed to functions:

a)

By value

b)

By reference

c)

By copy

d)

By pointer

e)

b and d

46.

Arrays are stored in memory:

a)

Randomly

b)

Sequentially

c)

In tree format

d)

As linked list

e)

Dynamically

47.

Which of these is true about array name?

a)

Acts as constant pointer

b)

Is a function

c)

Changes dynamically

d)

Is an object

e)

Is a macro