WorksheetsArray Quiz
Total questions: 47
Worksheet time: 24mins
Choose the correct way to declare an array in C.
array{10};
int array[10];
int array;
int array(10);
array int[10];
What will be the output of the following code? int arr[] = {1, 2, 3}; printf("%d", arr[1]);
1
2
3
Garbage value
Compilation error
What is the index of the last element in an array declared as int a[5];?
0
4
5
6
Depends on compiler
Which of the following accesses the third element in an array a?
a(3)
a.3
a[3]
a[2]
a->3
Which loop is best suited to access array elements sequentially?
if loop
for loop
goto
switch
continue
What will be the output of the following code? int a[3] = {10, 20, 30}; printf("%d", *(a + 1));
10
20
30
Address of a
Compilation error
What does sizeof(arr) return for int arr[5] = {1, 2, 3, 4, 5};?
5
10
20
4
Depends on system
Which of the following is not a valid array declaration?
int arr[10];
float marks[5];
char name[] = "John";
double data[3.5];
int matrix[2][2];
What is the result of this expression: arr[3] = *(arr + 3);?
Invalid syntax
Assigns a value
Causes segmentation fault
Returns array size
Swaps elements
How many elements are stored in int a[] = {1, 2, 3, 4};?
3
4
5
Cannot determine
0
Which operator is used to access elements in an array?
()
[]
{}
->
::
What will be printed by the code below? int a[5] = {0}; printf("%d", a[4]);
0
4
Garbage value
Compilation error
Runtime error
What will be the output of this code? int a[] = {10, 20, 30}; printf("%d", a[3]);
10
20
30
Garbage value
Compilation error
Arrays in C are:
Dynamically typed
Heterogeneous
Zero-indexed
One-indexed
Flexible in size
What is the size of int arr[10]; if int is 4 bytes?
10
20
40
50
100
Identify the correct syntax to input values into an array using a loop.
scanf("%d", arr[i]);
scanf("%d", &arr[i]);
cin >> arr[i];
input(arr[i]);
get(arr[i]);
Which header file is required for printf and scanf?
stdlib.h
string.h
stdio.h
conio.h
array.h
Which of these best describes an array in C?
Pointer
Structure
Class
File
None of the above
What will be the output? int a[3] = {1, 2, 3}; printf("%d", a[1] + a[2]);
3
5
6
2
4
Which statement is true about array indexing in C?
It starts at 1
It starts at 0
It starts at -1
It starts at 2
It's user-defined
Which expression refers to the first element of array a?
a[0]
*a
*(a + 0)
All of the above
a(0)
What happens if you access out-of-bound index in an array?
Returns 0
Returns NULL
Undefined behavior
Compilation error
Assigns 0
What is the default value of a static int array?
0
1
Garbage value
NULL
Undefined
Which of these correctly initializes all elements to 0?
int a[5] = {0};
int a[5];
int a[] = {1,2,3};
int a = {0};
int a[5] = {1};
What does *(arr + i) do?
Assigns a pointer
Refers to ith element
Declares array
Deletes array
Allocates memory
Array names in C act as:
Integers
Functions
Constants
Pointers
Classes
What will this print? int a[2][2] = {{1, 2}, {3, 4}}; printf("%d", a[1][0]);
1
2
3
4
Compilation error
What is the output? int a[5]; a[0] = 1; a[4] = 5; printf("%d", a[2]);
1
2
5
Garbage value
0
Which of the following correctly declares a 2D array?
int a(3,3);
int a{3}{3};
int a[3][3];
array int[3][3];
int a<3,3>;
What is the output? int a[] = {10, 20, 30, 40}; printf("%d", sizeof(a)/sizeof(a[0]));
2
3
4
5
Compilation error
Which access is correct in 2D array int a[2][3];?
a[2][3]
a[1][2]
a[3][2]
a(1,2)
a{1}{2}
What will be the output? int arr[3] = {5}; printf("%d", arr[2]);
0
5
3
Garbage
Compilation error
In C, which array declaration is invalid?
int a[3] = {1, 2};
int a[] = {1, 2, 3};
int a[2] = {1, 2, 3};
int a[3];
int a[0];
What happens when you assign a = &arr[0];?
Error
Assigns pointer
Allocates memory
Deletes value
Overwrites array
int *ptr = arr; means:
ptr is an array
ptr is a constant
ptr points to first element
ptr holds garbage
Compilation fails
Which of the following is correct?
*(arr + i) = arr[i]
arr[i] = i[arr]
Both a and b
Only b
Only a
The time complexity for accessing an array element is:
O(n)
O(log n)
O(1)
O(n log n)
O(n²)
Can array size be changed after declaration?
Yes
No
Only with malloc
Only with realloc
Only in Java
Array elements are stored in:
Heap
Stack
Queue
Hash
Tree
To pass an array to a function, use:
Pointers
Structures
Arrays can’t be passed
Classes
Files
Arrays in C are:
Objects
Functions
Homogeneous
Heterogeneous
None of these
Which one is a correct multidimensional array initialization?
int a[2][2] = {1, 2, 3, 4};
int a = [2][2];
int a{2}{2} = {{1,2},{3,4}};
int a(2,2) = {1,2,3,4};
array int[2][2];
What does int a[3] = {1}; initialize?
a[0]=1, a[1]=1, a[2]=1
All to 0
a[0]=1, a[1]=0, a[2]=0
Only a[0]=1
Compilation error
If int a[5] = {1, 2, 3, 4, 5};, then *(a + 4) is:
1
2
3
4
5
Arrays in C are passed to functions:
By value
By reference
By copy
By pointer
b and d
Arrays are stored in memory:
Randomly
Sequentially
In tree format
As linked list
Dynamically
Which of these is true about array name?
Acts as constant pointer
Is a function
Changes dynamically
Is an object
Is a macro
