wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz-5 AI

Total questions: 111

Worksheet time: 1hrs 20mins

Name
Class
Date
1.

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)

2.

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

b)

2

c)

4

d)

Error

3.

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

4.

What is the output of C Program.?

int main()

{

char grade[] = {'A','B','C'}; printf("GRADE=%c, ", *grade); printf("GRADE=%d", grade);

}

a)

GRADE=some address of array, GRADE=A

b)

GRADE=A, GRADE=some address of array

c)

GRADE=A, GRADE=A

d)

Compiler error

5.

What is the output of C program.?

int main() {

char grade[] = {'A','B','C'}; printf("GRADE=%d, ", *grade); printf("GRADE=%d", grade[0]);

}

a)

A A

b)

65 A

c)

65 65

d)

None

6.

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

7.

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

8.

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

9.

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

10.

What is the output of C program with arrays and pointers.?

int main() {

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

int *p[3];

p=&a;

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

a)

20

b)

address of element 20

c)

Garbage value

d)

Compiler error

11.
_________________ is a collection of elements used to store the same type of data.
a)
Array
b)
Switch
c)
Case
d)
Loop
12.
What is returned by values[5]?
a)
9
b)
12
c)
6
d)
8
13.
For the array:
float stats[3];
What is the range of the index?
a)
0 to 3
b)
0 to 2
c)
1 to 3
d)
0 to 4
14.
int nums[ ] =
{2, 3, 5, 8, 9, 11};
How would you access the fourth element in nums
a)
nums[4]
b)
nums[3]
c)
nums(4)
d)
nums(3)
15.
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
16.
What is the error in the following code fragment?
float average [20];
average[20] = 15.25;
a)
A cast is required
b)
data not initialized
c)
A two-dimensional array is required
d)
Array Out-of-bounds error
17.
________________________ are used to create a multi dimensional array.
a)
Single round brackets
b)
Single square brackets
c)
Multiple squares brackets
d)
Single angled brackets
18.
This is a:
a)
Linked list
b)
Stack
c)
2D array
d)
an array
19.
 Which of the following is a two-dimensional array?
a)
array anarray[20][20];
b)
int anarray[20][20];
c)
int array[20, 20];
d)
char array[20];
20.
Examine the following:
float values[ ][ ] =
{ {1.2, 9.0, 3.2},  
               {9.2, 0.5, 1.5, -1.2},  
      {7.3, 7.9, 4.8} } ;
what is in values[2][1]?
a)
7.3
b)
7.9
c)
9.2
d)
There is no such array element.
21.
Examine the following:
float values[ ][ ] = 
{ {1.2, 9.0, 3.2},  
               {9.2, 0.5, 1.5, -1.2},  
      {7.3, 7.9, 4.8} } ;
what is in values[3][0]?
a)
7.3
b)
7.9
c)
9.2
d)
There is no such array element.
22.
Examine the following:
int items[ ][ ] = 
{ {0,1,3,4} , {4,3,99,0,7} , {3,2} } ;
Which of the following statements replaces the 99 with 77?
a)
items[1][2] = 77;
b)
items[2][1] = 77;
c)
items[ 99 ] = 77;
d)
items[2][3] = 77;
23.



(a)  

24.
a)

8

b)

2

c)

9

d)

Error

e)

No output

25.
a)

1

b)

2

c)

No output

d)

Compilation Error

26.
a)

1 followed by garbage value

b)

1 1 1

c)

1 0 0

d)

Error

27.
a)

0

b)

1

c)

5

d)

garbage value

e)

Error

28.
a)

1,2,3

b)

4,5,6

c)

5,7,9

d)

Error

29.
a)

0

b)

1

c)

2

d)

3

e)

Error

30.
a)

30 30 garbage value

b)

30 30 30

c)

30 20 garbage value

d)

30 60 40

31.
a)

Garbage value

b)

0

c)

1

d)

Compiler dependent

32.



(a)  

33.



(a)  

34.



(a)  

35.

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}

36.

What will be the output after execution of the program?

(a)  

37.

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

(a)  

38.

What is Array?

a)

A. Collection of different type of elements

b)

B. Collectionof similar type of elements

c)

C. None of the above

d)

D. Both A and C

39.

What is right way to Initialize array?

a)

A. int num[6] = { 2, 4, 12, 5, 45, 5 };

b)

B. int n{} = { 2, 4, 12, 5, 45, 5 };

c)

C. int n{6} = { 2, 4, 12 };

d)

D. int n(6) = { 2, 4, 12, 5, 45, 5 };

40.

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

a)

A. Two

b)

B. eight

c)

C. sixteen

d)

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

41.

Which of the following function is more appropriate for reading in a multi-word string?

a)

scanf()

b)

gets()

c)

printf()

d)

puts()

42.

What is the starting index of an array in C?

a)

0

b)

1

c)

5

d)

4

43.

String is a

a)

Array of characters

b)

Array of integers

c)

Array of double

d)

All

44.

strcat()

a)

concatenates two strings

b)

Compare two strings

c)

find length

d)

all

45.

Finds the string length

a)

strcmp()

b)

strcpy()

c)

strlen()

d)

all

46.



(a)  

47.



(a)  

48.



(a)  

49.
a)

Compilation Error

b)

14

c)

13

d)

Garbage Value

50.
a)

321004

b)

3210

c)

01234

d)

400123

e)

432100

51.
a)

1 2 3 4 5 5

b)

1 2 3 4 5 0

c)

1 2 3 4 5 Garbage value

d)

Error

52.

int A[5][4];

What will be the size of above array element ?

(a)  

53.

Below is an example of -


int no[30][4];

a)

1-D Array

b)

2-D Array

c)

3-D Array

d)

4-D Array

54.

int A[2][2][2];

What will be the size of above array element ?

(a)  

55.

Pick all correct statements.

a)

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

b)

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

c)

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

d)

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

56.

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)

57.

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

58.

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

59.

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

60.

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

61.

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

62.

An array elements are always stored in ________ memory locations.

a)

sequential

b)

Random

c)

Sequential and Random

d)

None of the above

63.

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}

64.

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

65.

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

66.
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
67.

#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

68.

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

69.

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

70.

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

71.

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

72.

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

73.

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

74.

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

75.

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

76.

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.

77.

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

78.

When does the ArrayIndexOutOfBoundsException occur?

a)

Compile-time

b)

Run-time

c)

Not an error

d)

Not an exception at all

79.

a)

2,1,15

b)

1,2,5

c)

3,2,15

d)

2,3,20

80.

a)

5

b)

4

c)

6

d)

7

81.

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

82.

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

83.

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

84.

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.

85.

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

86.



(a)  

87.
a)

8

b)

2

c)

9

d)

Error

e)

No output

88.
a)

0

b)

1

c)

5

d)

garbage value

e)

Error

89.
a)

1,2,3

b)

4,5,6

c)

5,7,9

d)

Error

90.
a)

30 30 garbage value

b)

30 30 30

c)

30 20 garbage value

d)

30 60 40

91.
a)

Garbage value

b)

0

c)

1

d)

Compiler dependent

92.



(a)  

93.



(a)  

94.



(a)  

95.

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}

96.

What is the proper declaration for an array that has 2 rows and 3 columns?

a)

type arr[2][2];

b)

arr[2][3] type;

c)

type arr[2][3];

d)

type arr[4][3];

97.

How can I store the value 10 into the second row, first column of my array that I have declared as int numbers[10][10]?

a)

int numbers[1][2] = 10;

b)

numbers[1][2] = 10;

c)

numbers[2][3] = 10;

d)

numbers[1][0] = 10

98.



(a)  

99.
a)

Compilation Error

b)

14

c)

13

d)

Garbage Value

100.
a)

321004

b)

3210

c)

01234

d)

400123

e)

432100

101.
a)

1 2 3 4 5 5

b)

1 2 3 4 5 0

c)

1 2 3 4 5 Garbage value

d)

Error

102.

int A[5][4];

What will be the size of above array element ?

(a)  

103.

int A[2][2][2];

What will be the size of above array element ?

(a)  

104.

Pick all correct statements.

a)

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

b)

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

c)

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

d)

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

105.

if two strings are identical then function strcmp() returns

a)

0

b)

-1

c)

true

d)

none of these

106.

what will be the output of the program?

#include <stdio.h>

#include<string .h>

void main()

{

char str1[20]="Hello",str2="world";

strcat(str1,str2);

puts(str1);

return 0;

}

a)

Hello

b)

world

c)

Helloworld

d)

none of the above

107.

str1="6/4";

printf("str1");

a)

6/4

b)

str1

c)

None

108.

Which of the following function is more appropriate for reading in a multi-word string?

a)

scanf()

b)

printf()

c)

puts()

d)

gets()

109.

int main()

{

char str[25];

scanf("%s", str);

printf("%s",str);

return 0;

}

//input: South Africa

a)

South

b)

South Africa

c)

S

d)

Compiler error

110.

What is the output of C program with strings.?

int main()

{

char str1[]="SMART";

char str2[10];

str2 = str1;

printf("%s",str2);

return 0;

}

a)

SMART

b)

SMART followed by 5 spaces

c)

SMART followed by 4 spaces

d)

can not assign one string to another

111.

What will the output of the following program?

#include <stdio.h>

int main()

{

char str1[] = "College";

char str2[] = "University";

strcpy(str1, str2);

printf("%s", str1);

}

a)

College

b)

University

c)

College University

d)

University College