wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Arrays

Total questions: 85

Worksheet time: 2hrs 8mins

Name
Class
Date
1.



(a)  

2.
a)

8

b)

2

c)

9

d)

Error

e)

No output

3.
a)

1

b)

2

c)

No output

d)

Compilation Error

4.
a)

1 followed by garbage value

b)

1 1 1

c)

1 0 0

d)

Error

5.
a)

0

b)

1

c)

5

d)

garbage value

e)

Error

6.
a)

1,2,3

b)

4,5,6

c)

5,7,9

d)

Error

7.
a)

0

b)

1

c)

2

d)

3

e)

Error

8.
a)

30 30 garbage value

b)

30 30 30

c)

30 20 garbage value

d)

30 60 40

9.
a)

Garbage value

b)

0

c)

1

d)

Compiler dependent

10.



(a)  

11.



(a)  

12.



(a)  

13.

How to initialize an array in C? tick all the correct statement.

a)

int arr[3] = {1,2,3}

b)

int arr(3) = {1,2,3};

c)

int arr(3) = (1,2,3);

d)

int arr[3] = (1,2,3);

e)

int arr[3] = {0}

14.

What will be the output after execution of the program?

(a)  

15.

Assuming int is of 4 bytes, what is the size of int arr[12];?

(a)  

16.

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

17.

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

_____

a)

-1

b)

0

c)

1

d)

anything by the programmer

18.

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

a)

True

b)

False

19.

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

20.

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)

21.

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

22.

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

23.

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

24.

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

25.

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

26.

Array is a finite, ordered set of _______________elements.

a)

Heterogeneous

b)

Homogeneous

c)

None of the above

27.

In array we access the value of element using index.

a)

True

b)

False

28.

Largest value of the index is called _________________

a)

Lower bound

b)

Upper bound

c)

Index set

d)

value set

29.

In array we access each element exactly once is called_________

a)

Insertion

b)

Deletion

c)

Traversing

d)

None of the above

30.

formula for calculate the Length and the size or range of the array

a)

LB+UB

b)

UB-LB+!

c)

LB-UB+1

d)

None of the above

31.

The set of values of all array elements called_____________

a)

Index set

b)

Value set

c)

None of the above

32.

In array Index set is denoted by____

a)

T

b)

LB

c)

UB

d)

i

33.

An array where elements are referenced by two subscript called

a)

1-Dimensional array

b)

Two-Dimensional array

c)

none of the above

34.

How many possible ways to store 2-D array in computer memory?

a)

4

b)

3

c)

1

d)

2

35.

An array is called sparse array if it has a number of_________ elements.

a)

0

b)

1

c)

2

d)

3

36.

Using ____________ operation we can add the element at the end of the array.

a)

Deletion

b)

Traversing

c)

Insertion

d)

None of the above

37.

Address calculation of elements of 1-D array using

a)

BASE+(K-LB)*W

b)

BASE-(K-LB)*W

c)

BASE-(K+LB)*W

d)

BASE+(K+LB)*W

38.

Each element in an array can be accessed via its___________

a)

LB

b)

UB

c)

Index

d)

Value

39.

Array length is 10 which means it can store ________ elements.

a)

12

b)

10

c)

11

d)

9

40.

In which elements can be referenced by one subscript or index is called________________

a)

Linear array

b)

One dimensional array

c)

Both of the above

41.

Array is a collection of finite elements. Here Finite means

a)

not countable

b)

countable

42.

In array each element of the set has a unique position.

a)

True

b)

False

43.

In 2- d array a[4][3], Here 4 represents the number of _________?

a)

Columns

b)

Rows

c)

Index

d)

Value

44.

How many possible ways to stored 2-D array in computer memory?

a)

3

b)

1

c)

2

d)

4

45.

Address of the first element of the array is known as the ____________

a)

Base address

b)

Lower bound

c)

Upper bound

d)

none of the above.

46.

How do you initialize an array in C?

a)

int arr[3] = (1,2,3);

b)

int arr(3) = {1,2,3};

c)

int arr[3] = {1,2,3}

d)

int arr(3) = (1,2,3)

47.

What is the output of C Program.?

int main() {

int a[] = {1,2,3,4};

int b[4] = {5,6,7,8};

printf("%d,%d", a[0], b[0]);

}

a)

1,5

b)

2,6

c)

0,0

d)

Error

48.

What is the output of C program.?

int main()

{

float marks[3] = {90.5, 92.5, 96.5};

int a=0;

while(a<3)

{

printf("%.2f,", marks[a]); a++;

}

}

a)

90.5 92.5 96.5

b)

90.50 92.50 96.50

c)

0.00 0.00 0.00

d)

Compiler error

49.

What is the output of C Program.?

int main() {

int a[3] = {10,12,14};

a[1]=20;

int i=0;

while(i<3)

{ printf("%d ", a[i]);

i++; }

}

a)

20 12 14

b)

10 20 14

c)

10 12 20

d)

Error

50.

What is the output of C program.?

int main() {

int a[3] = {10,12,14};

int i=0;

while(i<3)

{ printf("%d ", i[a]);

i++; }

}

a)

14 12 10

b)

10 10 10

c)

10 12 14

d)

None

51.

What is the output of C program with arrays.?

int main() {

int a[3] = {20,30,40};

int b[3];

b=a;

printf("%d", b[0]);

}

a)

20

b)

30

c)

address of 0th element.

d)

Compiler error

52.

An array elements are always stored in ________ memory locations.

a)

sequential

b)

Random

c)

Sequential and Random

d)

None of the above

53.

8.Which of the following correctly accesses the seventh element stored in arr, an array with 100 elements?

a)

arr[6]

b)

arr[7]

c)

arr{6}

d)

arr{7}

54.

What is the minimum and maximum Indexes of this below array.?

int main()

{

int ary[9];

return 0;

}

a)

-1, 8

b)

0, 8

c)

1,9

d)

None of the above

55.

What is the output of this program

#include <stdio.h>

int main()

{ int a[2][] = { {1,1,1},{2,2,2}};

printf("%d", a[1][1]);

}

a)

1

b)

Error

c)

2

d)

0

56.
for(int i=0; i<10; i++)
           numbers[i] = 2 * i + 1;
// Which index of the array holds the value of 5?
a)
1
b)
2
c)
3
d)
4
57.

#include <stdio.h>

int main()

{

int arr[5];

// Assume base address of arr is 2000 and size of integer is 32 bit

printf("%u %u", arr + 1, &arr + 1);

return 0;

}


What is the o/p of the program?

a)

2004 2020

b)

2004 2004

c)

2004 Garbage value

d)

The program fails to compile because Address-of operator cannot be used with array name

58.

Which of the following statements are correct about an array?

1:The array int num[26]; can store 26 elements.

2:The expression num[1] designates the very first element in the array.

3:It is necessary to initialize the array at the time of declaration.

4:The declaration num[SIZE] is allowed if SIZE is a macro.

a)

1

b)

1,4

c)

2,4

d)

2,3

59.

Which of the following gives the memory address of the first element in array foo, an array with 100 elements?

a)

foo[0];

b)

foo;

c)

&foo;

d)

foo[1];

60.

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

61.

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

62.

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

63.

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

64.

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

65.

What is the output of C Program.?

int main() {

int a[];

a[4] = {1,2,3,4};

printf("%d", a[0]); }

a)

1

b)

2

c)

4

d)

Compiler Error

66.

What is the maximum number of dimensions an array in C may have?

a)

2

b)

8

c)

20

d)

50

e)

Theoratically no limit. The only practical limits are memory size and compilers.

67.

The parameter passing mechanism for an array is

a)

call by value

b)

call by reference

c)

call by value-result

d)

None of the above

68.

When does the ArrayIndexOutOfBoundsException occur?

a)

Compile-time

b)

Run-time

c)

Not an error

d)

Not an exception at all

69.

a)

2,1,15

b)

1,2,5

c)

3,2,15

d)

2,3,20

70.

a)

5

b)

4

c)

6

d)

7

71.

A one dimensional array A has indices 1....75.Each element is a string and takes up three memory words. The array is stored starting at location 1120 decimal. The starting address of A[49] is

a)

1167

b)

1164

c)

1264

d)

1169

72.

If storage class is missing in the array definition, by default it will be taken to be

a)

automatic

b)

external

c)

static

d)

either automatic or external depending on the place of occurrence

73.

he following program


main( )

{

static int a[ ] = { 7, 8, 9 } ;

printf( "%d", 2[ a ] + a[ 2 ] ) ;

}

a)

results in bus error

b)

results in segmentation voilation error

c)

will not compile successfully

d)

none of these

74.

Which statement is false?

a)

The brackets used to enclose the subscript of an array are not an operator in C.

b)

To refer to a particular element in an array, we specify the name of the array and the position number of the element in the array.

c)

The position number within an array is more formally called a subscript.

d)

“Array element seven” and the “seventh element of an array” do not mean the same thing. This is a frequent source of off-by-one errors.

75.

Choose a correct array statement.

a)

An array size can not changed once it is created.

b)

Array element value can be changed any number of times

c)

To access Nth element of an array students, use students[n-1] as the starting index is 0.

d)

All the above

76.



(a)  

77.
a)

8

b)

2

c)

9

d)

Error

e)

No output

78.
a)

0

b)

1

c)

5

d)

garbage value

e)

Error

79.
a)

1,2,3

b)

4,5,6

c)

5,7,9

d)

Error

80.
a)

30 30 garbage value

b)

30 30 30

c)

30 20 garbage value

d)

30 60 40

81.
a)

Garbage value

b)

0

c)

1

d)

Compiler dependent

82.



(a)  

83.



(a)  

84.



(a)  

85.

How to initialize an array in C? tick all the correct statement.

a)

int arr[3] = {1,2,3}

b)

int arr(3) = {1,2,3};

c)

int arr(3) = (1,2,3);

d)

int arr[3] = (1,2,3);

e)

int arr[3] = {0}