WorksheetsC Programming Array Quiz
Total questions: 10
Worksheet time: 5mins
What is the index of the first element in an array in C?
0
1
-1
Depends on the array size
What will be the output of the following code? int arr[5] = {1, 2, 3, 4, 5}; printf("%d", arr[2]);
1
2
3
4
Which of the following correctly declares an array in C?
int array;
array int[5];
int array[5];
int[5] array;
What is the output of the following code? int arr[3] = {10, 20, 30}; printf("%d", arr[5]);
10
30
Garbage value
Error
What is the size (in bytes) of the array int arr[10]; assuming int is 4 bytes?
10
40
4
14
Which of the following is used to access elements of an array in C?
( )
{ }
[ ]
What happens if you try to store more elements than declared in an array?
Compiler will expand the array
Runtime error
Compile-time error
Undefined behavior
Which of the following statements is true about arrays in C?
The size of an array can be changed at runtime
Array elements are stored in stack memory only
Array index can be negative
Array elements are stored in contiguous memory locations
How do you find the number of elements in an array int arr[10]; in C?
sizeof(arr)
sizeof(arr)/sizeof(int)
length(arr)
count(arr)
What is the correct way to initialize all elements of an array to 0?
int arr[10] = {0};
int arr[10] = (0);
int arr[10] = 0;
int arr[10]; arr = 0;
