Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C Array Basics Quiz

Total questions: 49

Worksheet time: 25mins

Name
Class
Date
1.

How do you declare an integer array of size 5 in C?

a)

int arr;

b)

int arr();

c)

array arr;

d)

int arr;

2.

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

a)

0

b)

1

c)

-1

d)

Depends on compiler

3.

To access the 4th element in an array arr, which syntax is correct?

a)

arr

b)

arr

c)

arr(3)

d)

arr

4.

What will sizeof(arr) return if int arr;?

a)

10

b)

40 (assuming 4 bytes per int)

c)

Number of elements

d)

Size of pointer

5.

How do you initialize an array with values 1, 2, 3?

a)

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

b)

int arr(3) = {1,2,3};

c)

int arr{1,2,3};

d)

int arr = ;

6.

What happens if you access arr in int arr;?

a)

Gives first element

b)

Undefined behavior (out-of-bounds)

c)

Compiler Error

d)

Returns 0

7.

Which loops can be used to iterate through all elements of an array?

a)

for loop

b)

while loop

c)

do-while loop

d)

All of the above

8.

What is the proper way to print all elements of int arr;?

a)

Loop with printf("%d", arr[i]);

b)

printf(arr);

c)

print(arr);

d)

scanf("%d", arr);

9.

How do you declare a two-dimensional array with 3 rows and 4 columns?

a)

int arr;

b)

int arr;

c)

int arr;

d)

int arr(3,4);

10.

First element of 2D array arr is accessed by?

a)

arr

b)

arr

c)

arr

d)

arr

11.

How to find the length of an array in C?

a)

sizeof(arr) / sizeof(arr)

b)

length(arr)

c)

arr.length

d)

Using loop count

12.

Which header file is needed to use printf for arrays?

a)

#include

b)

#include

c)

#include

d)

#include

13.

How do you pass an array to a function?

a)

Just the name of the array: function(arr);

b)

function(&arr);

c)

function(arr[])

d)

Both A and C are valid

14.

How do you declare an array of character with 10 elements?

a)

char arr;

b)

int arr;

c)

char arr();

d)

float arr;

15.

How to initialize a character array with "hello"?

a)

char arr[] = "hello";

b)

char arr[] = {'h','e','l','l','o'};

c)

Both A and B

d)

None of the above

16.

What does arr[i] represent in C?

a)

Pointer to element i

b)

Value at index i

c)

Address of element i

d)

Size of array

17.

What is the default value of uninitialized elements in a local array?

a)

0

b)

Garbage value

c)

NULL

d)

Depends on compiler

18.

How to copy an array in C?

a)

Using loop to copy element-wise

b)

Using strcpy

c)

Assign array directly

d)

Use memcpy or loop

19.

Which of these can index an array?

a)

Integer

b)

Float

c)

String

d)

Character

20.

How to declare an array when size is unknown and will be input?

a)

Use dynamic allocation (malloc)

b)

Fixed length declaration

c)

Use array of size 0

d)

Use pointer without allocation

21.

How do you print an array's address in C?

a)

printf("%p", arr);

b)

printf("%d", arr);

c)

printf(arr);

d)

printf("%s", arr);

22.

Expression arr++ in C?

a)

Increments pointer to next element

b)

Invalid, array name can't be incremented

c)

Moves array start by 1

d)

None of the above

23.

Which keyword defines a constant array?

a)

const

b)

static

c)

volatile

d)

register

24.

How to declare multi-dimensional array dynamically?

a)

Use pointers to pointers

b)

int arr[][];

c)

Fixed declaration

d)

Use #define

25.

Which function helps clear array content?

a)

memset

b)

memcpy

c)

strcpy

d)

free

26.

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

a)

0

b)

2

c)

Garbage

d)

Compilation error

27.

Which is valid index access for int arr;?

a)

arr

b)

arr

c)

arr[-1]

d)

arr

28.

How to initialize all elements to zero while declaring?

a)

int arr = {0};

b)

int arr = 0;

c)

int arr; memset(arr, 0, sizeof(arr));

d)

Both A and C

29.

Size of type int in array depends on?

a)

Compiler and machine architecture

b)

Array size

c)

Number of elements

d)

None of above

30.

How to declare an array and assign values later?

a)

int arr; arr=5;

b)

int arr[];

c)

arr = {1,2,3};

d)

array arr;

31.

What is the result of this code snippet? int arr[3] = {0}; printf("%d", arr[1]);

a)

Garbage value

b)

0

c)

Compiler error

d)

Undefined

32.

Which operator can be used as an alternative to array indexing arr[i]?

a)

*arr[i]

b)

*(arr + i)

c)

arr + i

d)

&arr[i]

33.

How do you declare a pointer to an array?

a)

int *ptr;

b)

int (*ptr);

c)

int ptr;

d)

int ptr();

34.

What will happen if the array is passed to a function and modified inside it?

a)

Changes reflect in the original array

b)

Changes do not reflect

c)

Compiler error

d)

Undefined behavior

35.

How to correctly scan input into an array of size 5?

a)

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

b)

scanf("%d", arr);

c)

scanf("%d %d %d %d %d", arr);

d)

None

36.

How to declare a global array?

a)

Outside all functions

b)

Inside main()

c)

Inside a function with static

d)

Both A and C

37.

How can you increase the size of an array after declaration?

a)

Use realloc() with dynamic arrays

b)

Increase size directly

c)

Use malloc() again

d)

Not possible in static arrays

38.

Initializing an integer array all elements to 5 directly?

a)

int arr = {5};

b)

Using a loop

c)

memset(arr, 5, sizeof(arr));

d)

None of the above

39.

What is the role of #define SIZE 10 in arrays?

a)

Defines size constant

b)

Declares array

c)

Sets initial values

d)

None

40.

Which header is required for memory allocation functions for dynamic arrays?

a)

#include

b)

#include

c)

#include

d)

#include

41.

How do you define an array inside a structure?

a)

struct S { int arr[5]; };

b)

struct S arr;

c)

int arr in struct

d)

None

42.

What is an array initializer list?

a)

List of values used when declaring array

b)

Loop for array input

c)

Function call

d)

Pointer to array

43.

The expression *(arr + 2) is?

a)

Access 2nd element (index 2)

b)

Access 1st element

c)

Compiler error

d)

Address of element 2

44.

What happens to array elements if declared static inside a function?

a)

Retains value between calls

b)

Resets each time

c)

Garbage values

d)

Compiler error

45.

Which function can be used to copy arrays?

a)

memcpy()

b)

strcpy()

c)

malloc()

d)

free()

46.

How do you declare an array of 10 floats?

a)

float arr;

b)

int arr;

c)

float arr();

d)

double arr;

47.

Can you assign a new array to an existing array variable?

a)

No

b)

Yes, with assignment

c)

Yes, using pointers

d)

Both B and C

48.

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

a)

1

b)

Address of arr

c)

4

d)

Garbage

49.

Why do arrays decay to pointers in C?

a)

To pass arrays to functions easily

b)

For arithmetic

c)

To save memory

d)

None