wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C-Lab-Arrays

Total questions: 10

Worksheet time: 4mins

Name
Class
Date
1.

Arrays are structures that hold multiple variables of the _____________ data type

a)

int data type

b)

char data type

c)

same data type

d)

different data type

2.

The first element in the array is by default numbered (index)

_____

a)

-1

b)

0

c)

1

d)

anything by the programmer

3.

Before using an array its type and dimension must be declared?

a)

True

b)

False

4.

int marks[30]; What the number 30 tells us

a)

int data type size

b)

number of elements in marks array

c)

maximum value, that can stored in marks

d)

None

5.

Which one is correct syntax for accessing value of 2nd element of an array

a)

int value = marks[1];

b)

int value = marks[2];

c)

int value = marks(1);

d)

int value = marks(2)

6.

Which one is correct syntax for entering 30 at 10th position of an array?

a)

marks[10]=30

b)

marks[9]=29

c)

marks[9]=30

d)

marks[10]=29

7.

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;

}

a)

1 1 1 1 1

b)

1 followed by 4 junk values

c)

1 0 0 0 0

d)

Compiler error

8.

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;

}

a)

Compiler error : Array index out of bound

b)

Prints 0 five times followed by garbage value

c)

Program will crash

d)

The program may print 0 five times followed by garbage value, or may crash if address (arr+5) is invalid

9.

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] )

a)

5 8 9 6 - 2 7 1 6

b)

5 8 9 6 -

6 1 7 2

c)

Error

d)

5 - 2

8 - 7

9 - 1

6 - 6

10.

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 ] );

a)

5 4 3 2 1 - one in each line

b)

5 4 3 2 - one in each line

c)

No output

d)

Never ending loop