wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Unit-2 Test-2

Total questions: 15

Worksheet time: 1hrs 21mins

Name
Class
Date
1.

What will be the output of the following C code?

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

int i = 0, j = 0;

for (i = 0; i < 2; i++)

for (j = 0; j < 3; j++)

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

a)

1 2 3 4 5 0

b)

1 2 3 4 5 junk

c)

1 2 3 4 5 5

d)

Run time error

2.

What will be the output of the following C code?

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

int i = 0, j = 0;

for (i = 0; i < 2; i++)

for (j = 0; j < 3; j++)

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

a)

1 2 3 junk 4 5

b)

Compile time error

c)

1 2 3 0 4 5

d)

1 2 3 3 4 5

3.

What will be the output of the following C code?

int a[2][3] = {0};

a[0][1] = 3;

int i = 0, j = 0;

for (i = 0; i < 2; i++)

for (j = 0; j < 3; j++)

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

a)

0 3 0 0 0 0

b)

Junk 3 junk junk junk junk

c)

Compile time error

d)

All junk values

4.

Which of the following is not possible statically in C?

a)

Jagged Array

b)

Rectangular Array

c)

Cuboidal Array

d)

Multidimensional Array

5.

What are the applications of a multidimensional array?

a)

Matrix-Multiplication

b)

Minimum Spanning Tree

c)

Finding connectivity between nodes

d)

All of the mentioned

6.

What will be the output of the following C code?

int ary[2][3];

ary[][] = {{1, 2, 3}, {4, 5, 6}};

printf("%d\n", ary[1][0]);

a)

Compile time error

b)

4

c)

1

d)

2

7.

What is the output of this program?

int a[10][20][30]={0};

printf("%ld", &a+1 - &a);

a)

1

b)

2

c)

0

d)

-1

8.

What is the output of the following program? (Assume input is 10)

int a;

printf("%d",scanf("%d",&a));

a)

1

b)

10

c)

0

d)

32647

9.

What will be the output of the following code?

unsigned int a = 5;

if(a > -1)

printf("5 is > -1\n");

a)

5 is > -1

b)

error

c)

nothing will be displayed in output

d)

none of the above

10.

What will be the output of the following code?

#include <stdio.h> int main() {

{ char a = 5; int b = 5; if(a == b) printf("char and int compared equal\n"); }

{ int a = 5; long int b = 5; if(a == b) printf("int and long compared equal\n"); }

{ float a = 5.0; double b = 5.0; if(a == b) printf("float and double compared equal\n"); }

{ float a = 5.2; double b = 5.2; if(a == b) printf("float and double again compared equal\n"); }

{ float a = 5.2; if(a == 5.2) printf("float compared equal with constant\n"); }

{ double a = 5.2; if(a == 5.2) printf("double compared equal with constant\n"); } return 0;}

a)

char and int compared equal

int and long compared equal

float and double compared equal

double compared equal with constant

b)

char and int compared equal

int and long compared equal

float and double compared equal

float compared equal with constant

double compared equal with constant

c)

char and int compared equal

int and long compared equal

float and double compared equal

float and double again compared equal

float compared equal with constant

double compared equal with constant

d)

float and double compared equal

float and double again compared equal

float compared equal with constant

double compared equal with constant

11.

The number of tokens in the following C statement. 

printf("i = %d, &i = %x", i, &i);

a)

3

b)

26

c)

10

d)

21

12.

Consider the following declaration of a ‘two-dimensional array in C:

char a[100][100];

Assuming that the main memory is byte-addressable and that the array is stored starting from memory address 0, the address of a[40][50] is

a)

4040

b)

4050

c)

5040

d)

5050

13.

Which combination of the integer variables x, y and z makes the variable a get the value 4 in the following expression?

a = (x > y)? ((x > z)? x : z): ((y > z)? y : z)

a)

x=3; y=4; z=2

b)

x=3; y=4; z=3

c)

x=6;y=3;z=5

d)

x=5; y=4; z=5

14.

Consider the C program given below. What does it print?

#include <stdio.h>

int main ()

{

        int i, j;

        int a [8] = {1, 2, 3, 4, 5, 6, 7, 8};

        for(i = 0; i < 3; i++) {

             a[i] = a[i] + 1;

             i++;

        }

        i--;

        for (j = 7; j > 4; j--) {

              int i = j/2;

              a[i] = a[i] - 1;

        }

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

}

a)

2,3

b)

2,4

c)

3,2

d)

3,3

15.

Consider the following snippet of a C program. Assume that swap(&x, &y)  exchanges the contents of x and y.

int main ()  {

int array[] = {3, 5, 1, 4, 6, 2};

int done = 0;

int i;

while (done == 0)  {

done = 1;

for (i=0; i<=4; i++)  {

if (array[i] < array[i+1])  {

swap (&array[i], &array[i+1]);

done = 0; } }

for (i=5; i>=1; i--)  {

if (array[i] > array[i-1])   {

swap(&array[i], &array[i-1]);

done=0; } } }

printf("%d", array[3]); }

a)

3

b)

4

c)

5

d)

6