WorksheetsC-Lab-Arrays
Total questions: 10
Worksheet time: 4mins
Arrays are structures that hold multiple variables of the _____________ data type
int data type
char data type
same data type
different data type
The first element in the array is by default numbered (index)
_____
-1
0
1
anything by the programmer
Before using an array its type and dimension must be declared?
True
False
int marks[30]; What the number 30 tells us
int data type size
number of elements in marks array
maximum value, that can stored in marks
None
Which one is correct syntax for accessing value of 2nd element of an array
int value = marks[1];
int value = marks[2];
int value = marks(1);
int value = marks(2)
Which one is correct syntax for entering 30 at 10th position of an array?
marks[10]=30
marks[9]=29
marks[9]=30
marks[10]=29
Predict output of following program
int main(){
int i;
int arr[5] = {1};
for (i = 0; i < 5; i++)
printf("%d ", arr[i]);
return 0;
}
1 1 1 1 1
1 followed by 4 junk values
1 0 0 0 0
Compiler error
What is the output of the following program?
int main()
{
int i; int arr[5] = {0};
for (i = 0; i <= 5; i++)
printf("%d ", arr[i]);
return 0;
}
Compiler error : Array index out of bound
Prints 0 five times followed by garbage value
Program will crash
The program may print 0 five times followed by garbage value, or may crash if address (arr+5) is invalid
What will be the output of the following code if array elements are: 5, 8, 9, 6, 1, 7, 2?
for(i=0, j=6; i<=(7/2) ; i++, j-- )
print(" %d - %d", array[i], array[j] )
5 8 9 6 - 2 7 1 6
5 8 9 6 -
6 1 7 2
Error
5 - 2
8 - 7
9 - 1
6 - 6
What will be the output of:
int a[] = { 5, 4, 3, 2, 1};
int i;
for(i=0; i>=3; i++)
printf("%d \n", a[ i ] );
5 4 3 2 1 - one in each line
5 4 3 2 - one in each line
No output
Never ending loop
