Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C Arrays Quiz

Total questions: 50

Worksheet time: 25mins

Name
Class
Date
1.

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

a)

int arr;

b)

array arr;

c)

int arr;

d)

int arr[];

2.

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

a)

0

b)

1

c)

-1

d)

n (array size)

3.

How do you initialize all elements of an integer array arr to zero?

a)

int arr = {0};

b)

int arr = (0,0,0,0,0);

c)

int arr;

d)

int arr; arr=0;

4.

What will happen if you access arr in an array declared as int arr;?

a)

It will access last element

b)

Compile-time error

c)

Unpredictable (undefined behavior)

d)

Produces zero output

5.

Which of these accesses the fifth element in the array arr?

a)

arr

b)

arr(5)

c)

arr{5}

d)

arr

6.

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

a)

2

b)

3

c)

4

d)

1

7.

If you declare int arr = {5}; what are the values in arr?

a)

5, 5, 5

b)

0, 0, 0

c)

5, 0, 0

d)

All garbage values

8.

Which header file is needed for printf when working with arrays?

a)

stdio.h

b)

stdlib.h

c)

array.h

d)

conio.h

9.

What is the maximum valid index for int arr;?

a)

100

b)

99

c)

101

d)

1

10.

Which for loop will traverse an array of n elements?

a)

for(i=0;i

b)

for(i=1;i<=n;i++)

c)

for(i=1;i

d)

for(i=0;i<=n;i++)

11.

How do you read n integers into an array arr using scanf?

a)

for(i=0;i

b)

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

c)

scanf("%d", arr);

d)

for(i=0;i

12.

What will sizeof(arr) return for int arr; declared locally?

a)

4

b)

10

c)

40

d)

14

13.

Can array elements be of different data types in C?

a)

Always

b)

Yes, if declared as void

c)

No

d)

Only in system arrays

14.

What is the correct way to print all elements of an array arr of size n?

a)

printf("%d", arr);

b)

for(i=0;i

c)

printf(arr);

d)

print(arr);

15.

Consider int arr = {2, 4}; What is arr?

a)

0

b)

Garbage

c)

2

d)

4

16.

Which operator is used to access elements in an array?

a)

()

b)

{}

c)

[]

d)

<>

17.

What will happen if array bounds are exceeded in C?

a)

Program terminates

b)

Runtime error with message

c)

Compile-time error

d)

Undefined behavior

18.

How would you sort an array arr[] of n elements in ascending order?

a)

Sort(arr)

b)

qsort(arr, n, sizeof(int), compare);

c)

sort(arr[], n);

d)

arr.sort();

19.

How does C store arrays in memory?

a)

Randomly

b)

Sequential blocks

c)

From end to start

d)

Not stored in memory

20.

What is the time complexity of accessing an element in an array?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n^2)

21.

Which statement about arrays is true?

a)

Arrays can have negative indices

b)

Size must be compile-time constant

c)

Arrays can resize at runtime

d)

Arrays are always sorted

22.

What is the result of int arr = {1,2,3,4,5}; printf("%d", arr);

a)

5

b)

Garbage value

c)

0

d)

Compile error

23.

What does the expression sizeof(arr)/sizeof(arr) find?

a)

Size of arr

b)

Number of elements in arr

c)

Address of arr

d)

Value of first element

24.

How do you reverse an array of integers in C?

a)

Use reverse(arr)

b)

Swap elements from start and end moving to center

c)

arr = arr[::-1]

d)

By using arr.reverse()

25.

Which loop is permitted to traverse an array in C?

a)

for

b)

while

c)

do-while

d)

All of the above

26.

What is the default value of elements in int arr; if not initialized?

a)

0

b)

1

c)

Undefined (garbage)

d)

-1

27.

In C, can array size be changed after declaration?

a)

Yes

b)

Only in dynamic arrays

c)

No

d)

Only in global arrays

28.

Given int arr[] = {1,2,3}; What is the size of arr?

a)

1

b)

2

c)

3

d)

4

29.

What will arr[-1] return for int arr;?

a)

First element

b)

Zero

c)

Compile error

d)

Unpredictable (undefined behavior)

30.

What is the output? c int arr[5]={1,2,3,4}; printf("%d",arr[4]);

a)

4

b)

0

c)

garbage

d)

Compile error

31.

How are multidimensional arrays declared in C?

a)

arr

b)

arr;

c)

arr{5,5};

d)

arr(5,5);

32.

What is the address of arr in array int arr;?

a)

&arr

b)

arr

c)

Both a and b

d)

Neither a nor b

33.

Which of the following best describes a 2D array?

a)

Array of integers

b)

Array of arrays

c)

Array of floats

d)

Array of structures

34.

Can you assign one array to another in C as arr1 = arr2;?

a)

Yes

b)

Only for same size

c)

No

d)

Only for int arrays

35.

What is the maximum number of elements in int arr;?

a)

16

b)

14

c)

15

d)

13

36.

If arr is an array, what is &arr?

a)

Last element's address

b)

Address of first element

c)

Address of 99th element

d)

Compile error

37.

What is the value of arr after this code? c int arr[2] = {10};

a)

10

b)

0

c)

1

d)

Garbage

38.

How can you find the sum of all elements in arr[] of length n?

a)

sum(arr)

b)

Add each element in a loop

c)

arr.sum()

d)

Use aggregate(arr)

39.

Which format specifier is used to print an element of an integer array?

a)

%d

b)

%c

c)

%f

d)

%s

40.

Which option best finds the largest element in arr[]?

a)

max(arr)

b)

Traverse all elements and compare

c)

arr.largest()

d)

max_element(arr)

41.

What is the main advantage of arrays?

a)

Dynamic resizing

b)

Store multiple values of same type efficiently

c)

Elements of different types

d)

Automatic sorting

42.

What is the data type of the index in arr?

a)

float

b)

char

c)

int

d)

double

43.

How are arrays passed to functions in C?

a)

By value

b)

By reference (as pointer to first element)

c)

By copy

d)

By address of entire array

44.

What is the output of sizeof(char arr);?

a)

10

b)

1

c)

100

d)

Undefined

45.

Can arrays be used with pointers in C?

a)

Yes

b)

No

c)

Only in C++

d)

For static arrays only

46.

What is the output of printf("%d", 3[arr]); if arr=15?

a)

0

b)

15

c)

3

d)

Compile error

47.

Which sorting algorithm is commonly used for small arrays?

a)

Quick sort

b)

Bubble sort

c)

Heap sort

d)

Merge sort

48.

What is the maximum memory size for int arr; if int occupies 4 bytes?

a)

10 bytes

b)

4 bytes

c)

14 bytes

d)

40 bytes

49.

Which function is commonly used to allocate memory for a dynamic array?

a)

malloc()

b)

allocate()

c)

calloc()

d)

Both a and c

50.

Which is correct about multidimensional array declaration?

a)

int arr[][];

b)

int arr;

c)

int arr;

d)

All of the above