WorksheetsEDIT
Total questions: 30
Worksheet time: 5mins
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); }
6
5
0
Varies
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); }
-2147483648
Runtime Error
8
-1
3) What will be the output?
void main() {
i=0x10+010+10;
printf("\nx=%x",i); }
I=34
X=22
X=34
Error
4) Int i=20;
Printf(“%X”,i);
What is the output?
20
15
14
Error
5) Print(max('quiz2code')
122
2
Z
C
6) What will the output of the following C code be?
#include int main() {
int k=8; int m=7; k
Runtime Error
Compiletime Error
8
7
7) What is the output of the following program?
#include<stdio.h>
main()
{
int a[] = {1,2}, *p = a;
printf("%d", p[1]);
}
Compile Error
1
Runtime Error
2
8) What is the output of the following program?
#include<stdio.h>
main()
{
int x = 3;
x += 2;
x =+ 2;
printf("%d", x);
}
2
5
7
Compile Error
9) #include int main() { int i = 1; if (i++ && (i == 1)) printf("No\n"); else printf("Yes\n"); }
Yes
No
Depends on the Compiler
Depends on the Standard
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)); }
0
20
Compile Error
Depends on Language standard
11) What will be the Output of the below code:
public class A {
public static void main(String[] args)
{
if (true)
break;
}
}
Nothing
Error
True
False
12) class Test {
public static void main(String[] args) {
for(int i = 0; 1; i++) {
System.out.println("Hello");
break;
}
}
}
Hello
Hello Hello
Compile Error
Runtime Error
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;
}
}
20
10
Error
Compile Error
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);
}
}
5
10
15
Error
15) What will the following code output?
public class DebuggingExample {
public static void main(String[] args) {
int x = 10;
System.out.println(x++); }}
Compilation Error
11
10
Runtime Error
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); }}
10
20
'a'
'b'
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);
}
}
True
Falls
Compilation fails
An exception is thrown at Runtime
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);
}
}
small
tiny
huge
Compilation fails
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 );
}
}
0
7
8
14
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);
}
}
2
8
4
16
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))
True False
False True
False False
True True
22) What is output of following code?
l = [1,2,6,5,7,8]
l.insert(9)
l=[1,2,6,5,7,8,9]
l=[1,2,6,5,9.7,8] (insert randomly at any position)
l=[9,1,2,6,5,7,8]
Type Error
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)
The program runs fine without error
Program displays 15 14 13 12 11
Program displays 11 12 13 14 15
Program displays 15 14 13 12 11 and then raises an index out of range exception
24) Find the output of the following program:
li = [1, 2, 3, 4]
li.append([5,6,7,8])
print(li)
[1,2,3,4,5,6,7,8]
[1,2,3,4]
[1,2,3,4,[5,6,7,8]]
[1,2,3,4][5,6,7,8]
25) Find the output of the following program:
def addToList(a):
a += [10]
b = [10, 20, 30, 40]
addToList(b)
print (len(b))
4
5
6
10
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])
[3, 2, 1, 0, 1, 4]
[0, 1, 0, 1, 4]
[0, 1]
[]
27) Find the output of the following program:
# statement 1
li = range(100, 110)
# statement 2
print (li.index(105))
5
104
105
106
28) Find the output of the following program:
a = [1, 2, 3, 4, 5]
b = a
b[0] = 0;
print(a)
[1, 2, 3, 4, 5, 0]
[0,1, 2, 3, 4, 5]
[0, 2, 3, 4, 5]
[1, 2, 3, 4, 0]
29) Find the output of the following program:
a = [1998, 2002]
b = [2014, 2016]
print ((a + b)*2)
[1998, 2002, 2014, 2016, 1998, 2002, 2014, 2016]
[1998, 2002, 2014, 2016]
[1998, 2002, 1998, 2002]
[2014, 2016, 2014, 2016]
30) a = ['physics', 'chemistry', 1997, 2000]
print (a[1][-1])
p
y
7
8
