WorksheetsC Arrays Quiz
Total questions: 50
Worksheet time: 25mins
Which of the following correctly declares an array of 10 integers in C?
int arr;
array arr;
int arr;
int arr[];
What is the index of the first element in a C array?
0
1
-1
n (array size)
How do you initialize all elements of an integer array arr to zero?
int arr = {0};
int arr = (0,0,0,0,0);
int arr;
int arr; arr=0;
What will happen if you access arr in an array declared as int arr;?
It will access last element
Compile-time error
Unpredictable (undefined behavior)
Produces zero output
Which of these accesses the fifth element in the array arr?
arr
arr(5)
arr{5}
arr
What is the output of the following code? c int arr[4] = {1,2,3,4}; printf("%d", arr[2]);
2
3
4
1
If you declare int arr = {5}; what are the values in arr?
5, 5, 5
0, 0, 0
5, 0, 0
All garbage values
Which header file is needed for printf when working with arrays?
stdio.h
stdlib.h
array.h
conio.h
What is the maximum valid index for int arr;?
100
99
101
1
Which for loop will traverse an array of n elements?
for(i=0;i
for(i=1;i<=n;i++)
for(i=1;i
for(i=0;i<=n;i++)
How do you read n integers into an array arr using scanf?
for(i=0;i
scanf("%d", arr[i]);
scanf("%d", arr);
for(i=0;i
What will sizeof(arr) return for int arr; declared locally?
4
10
40
14
Can array elements be of different data types in C?
Always
Yes, if declared as void
No
Only in system arrays
What is the correct way to print all elements of an array arr of size n?
printf("%d", arr);
for(i=0;i
printf(arr);
print(arr);
Consider int arr = {2, 4}; What is arr?
0
Garbage
2
4
Which operator is used to access elements in an array?
()
{}
[]
<>
What will happen if array bounds are exceeded in C?
Program terminates
Runtime error with message
Compile-time error
Undefined behavior
How would you sort an array arr[] of n elements in ascending order?
Sort(arr)
qsort(arr, n, sizeof(int), compare);
sort(arr[], n);
arr.sort();
How does C store arrays in memory?
Randomly
Sequential blocks
From end to start
Not stored in memory
What is the time complexity of accessing an element in an array?
O(1)
O(n)
O(log n)
O(n^2)
Which statement about arrays is true?
Arrays can have negative indices
Size must be compile-time constant
Arrays can resize at runtime
Arrays are always sorted
What is the result of int arr = {1,2,3,4,5}; printf("%d", arr);
5
Garbage value
0
Compile error
What does the expression sizeof(arr)/sizeof(arr) find?
Size of arr
Number of elements in arr
Address of arr
Value of first element
How do you reverse an array of integers in C?
Use reverse(arr)
Swap elements from start and end moving to center
arr = arr[::-1]
By using arr.reverse()
Which loop is permitted to traverse an array in C?
for
while
do-while
All of the above
What is the default value of elements in int arr; if not initialized?
0
1
Undefined (garbage)
-1
In C, can array size be changed after declaration?
Yes
Only in dynamic arrays
No
Only in global arrays
Given int arr[] = {1,2,3}; What is the size of arr?
1
2
3
4
What will arr[-1] return for int arr;?
First element
Zero
Compile error
Unpredictable (undefined behavior)
What is the output? c int arr[5]={1,2,3,4}; printf("%d",arr[4]);
4
0
garbage
Compile error
How are multidimensional arrays declared in C?
arr
arr;
arr{5,5};
arr(5,5);
What is the address of arr in array int arr;?
&arr
arr
Both a and b
Neither a nor b
Which of the following best describes a 2D array?
Array of integers
Array of arrays
Array of floats
Array of structures
Can you assign one array to another in C as arr1 = arr2;?
Yes
Only for same size
No
Only for int arrays
What is the maximum number of elements in int arr;?
16
14
15
13
If arr is an array, what is &arr?
Last element's address
Address of first element
Address of 99th element
Compile error
What is the value of arr after this code? c int arr[2] = {10};
10
0
1
Garbage
How can you find the sum of all elements in arr[] of length n?
sum(arr)
Add each element in a loop
arr.sum()
Use aggregate(arr)
Which format specifier is used to print an element of an integer array?
%d
%c
%f
%s
Which option best finds the largest element in arr[]?
max(arr)
Traverse all elements and compare
arr.largest()
max_element(arr)
What is the main advantage of arrays?
Dynamic resizing
Store multiple values of same type efficiently
Elements of different types
Automatic sorting
What is the data type of the index in arr?
float
char
int
double
How are arrays passed to functions in C?
By value
By reference (as pointer to first element)
By copy
By address of entire array
What is the output of sizeof(char arr);?
10
1
100
Undefined
Can arrays be used with pointers in C?
Yes
No
Only in C++
For static arrays only
What is the output of printf("%d", 3[arr]); if arr=15?
0
15
3
Compile error
Which sorting algorithm is commonly used for small arrays?
Quick sort
Bubble sort
Heap sort
Merge sort
What is the maximum memory size for int arr; if int occupies 4 bytes?
10 bytes
4 bytes
14 bytes
40 bytes
Which function is commonly used to allocate memory for a dynamic array?
malloc()
allocate()
calloc()
Both a and c
Which is correct about multidimensional array declaration?
int arr[][];
int arr;
int arr;
All of the above
