wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

EDIT

Total questions: 30

Worksheet time: 5mins

Name
Class
Date
1.

1) What is the output of this C code?

#include void main() {

int x=1, y=0, z=5;

int a=x&&y||z++;

printf("%d",z); }

a)

6

b)

5

c)

0

d)

Varies

2.

2) What is the output of this C code?

#include void main() {

int x=1, z=3;

int y=x<<3;

printf("%d\n",y); }

a)

-2147483648

b)

Runtime Error

c)

8

d)

-1

3.

3) What will be the output?

void main() {

i=0x10+010+10;

printf("\nx=%x",i); }

a)

I=34

b)

X=22

c)

X=34

d)

Error

4.

4) Int i=20;

Printf(“%X”,i);

What is the output?

a)

20

b)

15

c)

14

d)

Error

5.

5) Print(max('quiz2code')

a)

122

b)

2

c)

Z

d)

C

6.

6) What will the output of the following C code be?

#include int main() {

int k=8; int m=7; k

a)

Runtime Error

b)

Compiletime Error

c)

8

d)

7

7.

7) What is the output of the following program?

#include<stdio.h>

main()

{

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

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

}

a)

Compile Error

b)

1

c)

Runtime Error

d)

2

8.

8) What is the output of the following program?

#include<stdio.h>

main()

{

int x = 3;

x += 2;

x =+ 2;

printf("%d", x);

}

a)

2

b)

5

c)

7

d)

Compile Error

9.

9) #include int main() { int i = 1; if (i++ && (i == 1)) printf("No\n"); else printf("Yes\n"); }

a)

Yes

b)

No

c)

Depends on the Compiler

d)

Depends on the Standard

10.

10) What will be the final value of J in the following C code?

#include<stdio.h>

int main() { int i=10,j=0; if(I||(J=I+10)); }

a)

0

b)

20

c)

Compile Error

d)

Depends on Language standard

11.

11) What will be the Output of the below code:

public class A {

public static void main(String[] args)

{

if (true)

break;

}

}

a)

Nothing

b)

Error

c)

True

d)

False

12.

12) class Test {

public static void main(String[] args) {

for(int i = 0; 1; i++) {

System.out.println("Hello");

break;

}

}

}

a)

Hello

b)

Hello Hello

c)

Compile Error

d)

Runtime Error

13.

13) Predict the output of the following Java Program class Main {

public static void main(String args[]) {

System.out.println(fun());

}

static int fun() {

return 20;

}

}

a)

20

b)

10

c)

Error

d)

Compile Error

14.

14) Predict the output of the following Java Program class Test {

int x = 10;

public static void main(String[] args)

{

Test t = new Test();

System.out.println(t.x);

}

}

a)

5

b)

10

c)

15

d)

Error

15.

15) What will the following code output?

public class DebuggingExample {

public static void main(String[] args) {

int x = 10;

System.out.println(x++); }}

a)

Compilation Error

b)

11

c)

10

d)

Runtime Error

16.

16) What does the following code snippet print?

public class DebuggingExample {

public static void main(String[] args) {

int a = 10; int b = 20;

System.out.println(a < b ? a : b); }}

a)

10

b)

20

c)

'a'

d)

'b'

17.

17) What will be the output of the program?

class Equals

{

public static void main(String [] args)

{

int x = 100;

double y = 100.1;

boolean b = (x = y); /* Line 7 */

System.out.println(b);

}

}

a)

True

b)

Falls

c)

Compilation fails

d)

An exception is thrown at Runtime

18.

18) What will be the output of the program?

class Test

{

public static void main(String [] args)

{

int x=20;

String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";

System.out.println(sup);

}

}

a)

small

b)

tiny

c)

huge

d)

Compilation fails

19.

19) What will be the output of the program?

class Bitwise

{

public static void main(String [] args)

{

int x = 11 & 9;

int y = x ^ 3;

System.out.println( y | 12 );

}

}

a)

0

b)

7

c)

8

d)

14

20.

20) What will be the output of the program?

public class Test

{

public static void leftshift(int i, int j)

{

i <<= j;

}

public static void main(String args[])

{

int i = 4, j = 2;

leftshift(i, j);

System.out.println(i);

}

}

a)

2

b)

8

c)

4

d)

16

21.

21) What will be the output of the following code? class Count:

def init(self, count=0):

self.__count=count

a=Count(2)

b=Count(2)

print(id(a)==id(b), end = '' '')

c= ''hello''

d= ''hello''

print(id(c)==id(d))

a)

True False

b)

False True

c)

False False

d)

True True

22.

22) What is output of following code?

l = [1,2,6,5,7,8]

l.insert(9)

a)

l=[1,2,6,5,7,8,9]

b)

l=[1,2,6,5,9.7,8] (insert randomly at any position)

c)

l=[9,1,2,6,5,7,8]

d)

Type Error

23.

23) What is the out of the code?

def rev_func(x,length):

print(x[length-1],end='' '')

rev_func(x,length-1)

x=[11, 12, 13, 14, 15]

rev_func(x,5)

a)

The program runs fine without error

b)

Program displays 15 14 13 12 11

c)

Program displays 11 12 13 14 15

d)

Program displays 15 14 13 12 11 and then raises an index out of range exception

24.

24) Find the output of the following program:

li = [1, 2, 3, 4]

li.append([5,6,7,8])

print(li)

a)

[1,2,3,4,5,6,7,8]

b)

[1,2,3,4]

c)

[1,2,3,4,[5,6,7,8]]

d)

[1,2,3,4][5,6,7,8]

25.

25) Find the output of the following program:

def addToList(a):

a += [10]

b = [10, 20, 30, 40]

addToList(b)

print (len(b))

a)

4

b)

5

c)

6

d)

10

26.

26) Find the output of the following program:

def gfg(x,li=[]):

for i in range(x):

li.append(i*i)

print(li)

gfg(3,[3,2,1])

a)

[3, 2, 1, 0, 1, 4]

b)

[0, 1, 0, 1, 4]

c)

[0, 1]

d)

[]

27.

27) Find the output of the following program:

# statement 1

li = range(100, 110)

# statement 2

print (li.index(105))

a)

5

b)

104

c)

105

d)

106

28.

28) Find the output of the following program:

a = [1, 2, 3, 4, 5]

b = a

b[0] = 0;

print(a)

a)

[1, 2, 3, 4, 5, 0]

b)

[0,1, 2, 3, 4, 5]

c)

[0, 2, 3, 4, 5]

d)

[1, 2, 3, 4, 0]

29.

29) Find the output of the following program:

a = [1998, 2002]

b = [2014, 2016]

print ((a + b)*2)

a)

[1998, 2002, 2014, 2016, 1998, 2002, 2014, 2016]

b)

[1998, 2002, 2014, 2016]

c)

[1998, 2002, 1998, 2002]

d)

[2014, 2016, 2014, 2016]

30.

30) a = ['physics', 'chemistry', 1997, 2000]

print (a[1][-1])

a)

p

b)

y

c)

7

d)

8