wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Skill Development - Debugging Practice1

Total questions: 10

Worksheet time: 10mins

Name
Class
Date
1.

What will be the final value of x in the following C code?

#include <stdio.h>

void main()

{

int x = 5 * 9 / 3 + 9;

}

a)

3.75

b)

Depends on Compiler

c)

24

d)

3

2.

How many times i value is checked in the following C program?

#include <stdio.h>

int main()

{

int i = 0;

while (i < 3)

i++;

printf("In while loop\n");

}

a)

2

b)

3

c)

4

d)

1

3.

What is the output of this C code?

#include <stdio.h>

main()

{

int n = 0, m = 0;

if (n > 0)

if (m > 0)

printf("True");

else

printf("False");

}

a)

True

b)

False

c)

No Output will be Printed

d)

Run Time Error

4.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

int a = 1, b = 1, c;

c = a++ + b;

printf("%d, %d", a, b);

}

a)

a = 1, b = 1

b)

a = 2, b = 1

c)

a = 1, b = 2

d)

a = 2, b = 2

5.

What will be the output of the following C# code?

int i, j = 1, k;

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

{

k = j++ - ++j;

Console.Write(k + " ");

}

a)

-4 -2 -2

b)

-6 -4 -1

c)

-2 -2 -2

d)

-4 -4 -4

6.

Find out the error, if any in the below program?

#include<stdio.h>

int main()

{

int i = 1;

switch(i)

{

case 1:

printf("Case1");

break;

case 1*2+2:

printf("Case2");

break;

}

return 0;

}

a)

Error: in switch statement

b)

Error: in case 1*2+4 statement

c)

Error: No default specified

d)

No Error

7.

What will be the output of the following C# code?

struct abc

{

int i;

}

class Program

{

static void Main(string[] args)

{

abc x = new abc();

abc z;

x.i = 10;

z = x;

z.i = 15;

console.Writeline(x.i + " " + y.i)

}

}

a)

10 10

b)

10 15

c)

15 10

d)

15 15

8.

1. What will be the output of the following code snippet?

using System;

class program

{

static void Main(string[] args)

{

int x = 8;

int b = 16;

int c = 64;

x /= c /= b;

Console.WriteLine(x + " " + b+ " " +c);

Console.ReadLine();

}

}

a)

2 16 4

b)

4 8 16

c)

2 4 8

d)

8 16 64

9.

What will be the output of the following C# code?

static void Main(string[] args)

{

int i, j;

int[, ] arr = new int[ 3, 3];

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

{

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

{

arr[i, j] = i * 2 + i * 2;

Console.WriteLine(arr[i, j]);

}

Console.ReadLine();

}

}

a)

0, 0, 0 4, 4, 4 8, 8, 8

b)

4, 4, 4 8, 8, 8 12, 12, 12

c)

. 8, 8, 8 12, 12, 12 16, 16, 16

d)

0, 0, 0 1, 1, 1 2, 2, 2

10.

Which is the correct way of defining and initializing an array of 3 integers?

a)

int[] a={78, 54};

b)

int[] a;

a = new int[3];

a[1] = 78;

a[2] = 9;

a[3] = 54

c)

int[ ]a;

a = new int{78, 9, 54};

d)

int[ ] a;

a = new int[3]{78, 9, 54};