0% found this document useful (0 votes)
3 views39 pages

Basic Coding Output MCQs

The document contains a series of multiple-choice questions (MCQs) related to basic coding concepts in C, C++, and Python. Each question presents a code snippet and four possible outputs, with the correct answer indicated for each. The questions cover various topics including data types, control structures, operators, and output formatting.

Uploaded by

s.kumar02cse
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views39 pages

Basic Coding Output MCQs

The document contains a series of multiple-choice questions (MCQs) related to basic coding concepts in C, C++, and Python. Each question presents a code snippet and four possible outputs, with the correct answer indicated for each. The questions cover various topics including data types, control structures, operators, and output formatting.

Uploaded by

s.kumar02cse
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Basic Coding Output MCQs

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


#include<stdio.h>
int main() {
printf("Hello World");
return 0;
}

A) Hello​
B) World​
C) Hello World​


D) Error​
Answer: C) Hello World

2. What will be the output?


#include<stdio.h>
int main(){
int a = 5, b = 10;
printf("%d", a + b);
}

A) 15​
B) 5​
C) 10​


D) Error​
Answer: A) 15

3. What will be printed?


#include<stdio.h>
int main(){
int a = 10;
printf("%d", ++a);
}

A) 10​
B) 11​
C) 9​


D) Error​
Answer: B) 11

4. What is the output of the following?


#include<stdio.h>
int main(){
int a = 5;
printf("%d", a++);
}

A) 6​
B) 5​
C) 4​


D) Error​
Answer: B) 5

5. Output of this code:


#include<stdio.h>
int main(){
int a = 3, b = 2;
printf("%d", a * b + b);
}

A) 6​
B) 8​
C) 10​


D) 7​
Answer: D) 8
6. Find the output:
#include<stdio.h>
int main(){
int x = 5;
x += 2;
printf("%d", x);
}

A) 5​
B) 7​
C) 2​


D) 10​
Answer: B) 7

7. What is the output?


#include<stdio.h>
int main(){
int a = 10;
printf("%d %d", a, a++);
}

A) 10 11​
B) 11 10​
C) 10 10​


D) Undefined​
Answer: D) Undefined (compiler-dependent)

8. Output:
#include<stdio.h>
int main(){
int a = 1;
if(a)
printf("True");
else
printf("False");
}

A) True​
B) False​
C) Error​


D) Blank​
Answer: A) True

9. Find the output:


#include<stdio.h>
int main(){
int x = 0;
if(x)
printf("A");
else
printf("B");
}

A) A​
B) B​
C) 0​


D) Error​
Answer: B) B

10. What will be printed?


#include<stdio.h>
int main(){
int a = 10, b = 20;
if(a < b)
printf("Smaller");
else
printf("Greater");
}
A) Greater​
B) Smaller​
C) Equal​


D) Error​
Answer: B) Smaller

11. What will this loop print?


#include<stdio.h>
int main(){
for(int i = 1; i <= 3; i++)
printf("%d ", i);
}

A) 1 2 3​
B) 0 1 2 3​
C) 1 2​


D) 3 2 1​
Answer: A) 1 2 3

12. Output of the following code:


#include<stdio.h>
int main(){
int i = 1;
while(i <= 3){
printf("%d ", i);
i++;
}
}

A) 1 2 3​
B) 1 2​
C) 3 2 1​


D) Infinite loop​
Answer: A) 1 2 3
13. What will be printed?
#include<stdio.h>
int main(){
for(int i = 1; i <= 3; i++){
if(i == 2)
continue;
printf("%d ", i);
}
}

A) 1 2 3​
B) 1 3​
C) 2 3​


D) 3 1​
Answer: B) 1 3

14. Output:
#include<stdio.h>
int main(){
int i = 1;
do {
printf("%d ", i);
i++;
} while(i < 3);
}

A) 1 2​
B) 1​
C) 1 2 3​


D) Infinite​
Answer: A) 1 2

15. What is printed?


#include<stdio.h>
int main(){
int i = 1;
while(i < 3)
printf("%d", i++);
}

A) 1 2​
B) 2​
C) 1​


D) 0​
Answer: A) 1 2

16. Output of the code:


#include<stdio.h>
int main(){
int a = 5, b = 2;
printf("%d", a / b);
}

A) 2​
B) 2.5​
C) 3​


D) 5​
Answer: A) 2

17. What is the output?


#include<stdio.h>
int main(){
float a = 5.0 / 2;
printf("%.1f", a);
}

A) 2​
B) 2.5​
C) 3​

D) 2.0​
Answer: B) 2.5

18. Output:
#include<stdio.h>
int main(){
int x = 10;
printf("%d", x == 10);
}

A) 1​
B) 0​
C) 10​


D) Error​
Answer: A) 1

19. What will print?


#include<stdio.h>
int main(){
printf("%d", sizeof(int));
}

A) 2 or 4 (depends on system)​
B) 8​
C) 16​


D) Error​
Answer: A) 2 or 4 (depends on compiler)

20. Output of code:


#include<stdio.h>
int main(){
char c = 'A';
printf("%d", c);
}
A) 65​
B) A​
C) a​


D) Error​
Answer: A) 65

21. Output:
#include<stdio.h>
int main(){
char c = 66;
printf("%c", c);
}

A) B​
B) 66​
C) b​


D) A​
Answer: A) B

22. Output:
#include<stdio.h>
int main(){
int a = 10, b = 20;
printf("%d", a > b ? a : b);
}

A) 10​
B) 20​
C) 0​


D) Error​
Answer: B) 20

23. What will print?


#include<stdio.h>
int main(){
int a = 5;
printf("%d", a == 5 && a < 10);
}

A) 1​
B) 0​
C) 5​


D) Error​
Answer: A) 1

24. Output of:


#include<stdio.h>
int main(){
printf("%d", 5 | 3);
}

A) 7​
B) 8​
C) 5​


D) 2​
Answer: A) 7

25. What is the output?


#include<stdio.h>
int main(){
printf("%d", 5 & 3);
}

A) 1​
B) 7​
C) 0​


D) 2​
Answer: D) 1
26. Output:
#include<stdio.h>
int main(){
printf("%d", 4 << 1);
}

A) 8​
B) 4​
C) 2​


D) 1​
Answer: A) 8

27. Output:
#include<stdio.h>
int main(){
printf("%d", 8 >> 2);
}

A) 2​
B) 4​
C) 8​


D) 1​
Answer: A) 2

28. What will be printed?


#include<stdio.h>
int main(){
int a = 2;
switch(a){
case 1: printf("One"); break;
case 2: printf("Two"); break;
default: printf("Default");
}
}

A) One​
B) Two​
C) Default​


D) Error​
Answer: B) Two

29. Output:
#include<stdio.h>
int main(){
int a = 3;
switch(a){
case 1: printf("One");
case 2: printf("Two");
case 3: printf("Three");
}
}

A) Three​
B) One​
C) Two​


D) Three (and no break means fall-through)​
Answer: D) Three (and also continues until end — prints “Three”)

30. Output:
#include<stdio.h>
int main(){
int x = 3;
if(x % 2 == 0)
printf("Even");
else
printf("Odd");
}
A) Even​
B) Odd​
C) 3​


D) Error​
Answer: B) Odd

31. What will be the output?


#include<stdio.h>
int main(){
int i;
for(i=0; i<5; i++);
printf("%d", i);
}

A) 0 1 2 3 4​
B) 5​
C) 4​


D) Infinite loop​
Answer: B) 5​
(Because of semicolon after for loop, body not executed)

32. What will this code print?


#include<stdio.h>
int main(){
int i=1;
while(i<3);
i++;
printf("%d", i);
}

A) 3​
B) 1​
C) Infinite loop​


D) 2​
Answer: C) Infinite loop​
(Because of semicolon after while)
33. Output of this code:
#include<stdio.h>
int main(){
int x = 10;
x = x++;
printf("%d", x);
}

A) 10​
B) 11​
C) 9​


D) Undefined​
Answer: D) Undefined (compiler-dependent behavior)

34. Output:
#include<stdio.h>
int main(){
int x=2, y=5;
printf("%d", x == 2 && y > 2);
}

A) 1​
B) 0​
C) 2​


D) 5​
Answer: A) 1

35. What is printed?


#include<stdio.h>
int main(){
int x=3, y=4;
printf("%d", x | y);
}
A) 7​
B) 4​
C) 3​


D) 5​
Answer: A) 7

36. Output:
#include<stdio.h>
int main(){
int a=1, b=0;
printf("%d", a && b);
}

A) 0​
B) 1​
C) True​


D) False​
Answer: A) 0

37. What is the output?


#include<stdio.h>
int main(){
int a=5;
printf("%d", !a);
}

A) 0​
B) 1​
C) -1​


D) Error​
Answer: A) 0

38. What will print?


#include<stdio.h>
int main(){
int i = 10;
printf("%d %d", i++, ++i);
}

A) Undefined​
B) 10 12​
C) 11 11​


D) 10 11​
Answer: A) Undefined

39. Output of:


#include<stdio.h>
int main(){
printf("%d", 10>5 ? 1 : 0);
}

A) 1​
B) 0​
C) 10​


D) 5​
Answer: A) 1

40. Output:
#include<stdio.h>
int main(){
int a = 5, b = 2;
float c = a / b;
printf("%.1f", c);
}

A) 2.0​
B) 2.5​
C) 2.3​

D) Error​
Answer: A) 2.0​
(Integer division before float conversion)

41. What will the code print?


#include<iostream>
using namespace std;
int main(){
cout << "Hello C++";
}

A) Hello C++​
B) Error​
C) C++​


D) Nothing​
Answer: A) Hello C++

42. Output:
#include<iostream>
using namespace std;
int main(){
int a = 10, b = 20;
cout << a + b;
}

A) 30​
B) 10​
C) 20​


D) 0​
Answer: A) 30

43. Output of this C++ code:


#include<iostream>
using namespace std;
int main(){
int a = 5;
cout << ++a;
}

A) 5​
B) 6​
C) 4​


D) Error​
Answer: B) 6

44. Output:
#include<iostream>
using namespace std;
int main(){
int x = 10, y = 5;
cout << (x > y ? x : y);
}

A) 10​
B) 5​
C) 0​


D) Error​
Answer: A) 10

45. Output of this:


#include<iostream>
using namespace std;
int main(){
int a = 3, b = 2;
cout << a / b;
}

A) 1​
B) 1.5​
C) 2​


D) 0​
Answer: A) 1

46. Output:
#include<iostream>
using namespace std;
int main(){
float a = 3, b = 2;
cout << a / b;
}

A) 1.5​
B) 1​
C) 2​


D) 0​
Answer: A) 1.5

47. What is printed?


#include<iostream>
using namespace std;
int main(){
int x = 10;
cout << x++;
}

A) 10​
B) 11​
C) 9​


D) Error​
Answer: A) 10

48. Output:
#include<iostream>
using namespace std;
int main(){
string s = "Hello";
cout << [Link]();
}

A) 5​
B) 6​
C) 4​


D) Error​
Answer: A) 5

49. What is output of following Python code?


print(5 + 10)

A) 15​
B) 510​
C) Error​


D) None​
Answer: A) 15

50. Output:
print("Hello" + "World")

A) Hello World​
B) HelloWorld​
C) Error​


D) Hello+World​
Answer: B) HelloWorld

51. Output:
print(10/3)
A) 3​
B) 3.3​
C) 3.3333333333333335​


D) Error​
Answer: C) 3.3333333333333335

52. Output:
print(10//3)

A) 3​
B) 3.33​
C) 4​


D) Error​
Answer: A) 3

53. Output:
x = 5
x += 2
print(x)

A) 7​
B) 5​
C) 2​


D) Error​
Answer: A) 7

54. What will be printed?


x = "5"
y = 2
print(x * y)

A) 55​
B) 10​
C) 5*2​

D) 55 (string repeated twice)​
Answer: D) 55

55. Output of this Python code:


a = 10
b = 20
print(a > b)

A) True​
B) False​
C) 1​


D) 0​
Answer: B) False

56. Output:
x = 5
if x % 2 == 0:
print("Even")
else:
print("Odd")

A) Even​
B) Odd​
C) Error​


D) None​
Answer: B) Odd

57. What is printed?


for i in range(3):
print(i, end=" ")

A) 0 1 2​
B) 1 2 3​
C) 0 1 2 3​

D) Error​
Answer: A) 0 1 2

58. Output:
for i in range(2, 5):
print(i)

A) 2 3 4​
B) 2 3 4 5​
C) 1 2 3​


D) Error​
Answer: A) 2 3 4

59. Output:
i = 0
while i < 3:
print(i)
i += 1

A) 0 1 2​
B) 1 2 3​
C) 0 1 2 3​


D) Error​
Answer: A) 0 1 2

60. Output of this code:


a = [1, 2, 3]
print(len(a))

A) 3​
B) 2​
C) 4​


D) Error​
Answer: A) 3
61. Output:
a = [1, 2, 3]
print(a[1])

A) 1​
B) 2​
C) 3​


D) Error​
Answer: B) 2

62. Output:
x = [1, 2, 3]
print(x[-1])

A) 3​
B) 2​
C) 1​


D) Error​
Answer: A) 3

63. Output of:


x = (1, 2, 3)
x[1] = 5
print(x)

A) Error (tuple is immutable)​


B) (1,5,3)​
C) (1,2,3)​


D) None​
Answer: A) Error

64. Output:
x = {"a":1, "b":2}
print(x["a"])

A) 1​
B) 2​
C) a​


D) Error​
Answer: A) 1

65. Output:
x = set([1,2,2,3])
print(len(x))

A) 3​
B) 4​
C) 2​


D) Error​
Answer: A) 3

66. Output:
print(type(3.0))

A) <class 'float'>​
B) int​
C) double​


D) long​
Answer: A) <class 'float'>

67. Output:
print(bool(0))

A) False​
B) True​
C) 0​


D) 1​
Answer: A) False

68. Output:
print(2 ** 3)

A) 6​
B) 8​
C) 9​


D) 4​
Answer: B) 8

69. Output of:


print("A" * 3)

A) AAA​
B) A3​
C) Error​


D) A A A​
Answer: A) AAA

70. Output:
def add(a,b=2):
print(a+b)
add(3)

A) 5​
B) 3​
C) Error​


D) None​
Answer: A) 5
71. Output:
def test(x):
return x*x
print(test(4))

A) 16​
B) 8​
C) 4​


D) Error​
Answer: A) 16

72. Output:
public class Main {
public static void main(String[] args) {
[Link]("Hello Java");
}
}

A) Hello Java​
B) Hello​
C) Java​


D) Error​
Answer: A) Hello Java

73. Output:
class A {
public static void main(String args[]) {
int x = 5, y = 2;
[Link](x / y);
}
}

A) 2​
B) 2.5​
C) Error​

D) 0​
Answer: A) 2

74. Output:
class A {
public static void main(String args[]) {
int x = 5;
[Link](++x);
}
}

A) 5​
B) 6​
C) 7​


D) Error​
Answer: B) 6

75. Output:
class A {
public static void main(String args[]) {
String s = "Hello";
[Link]([Link]());
}
}

A) 5​
B) 4​
C) 6​


D) Error​
Answer: A) 5

76. Output:
class A {
public static void main(String args[]) {
int x = 10;
if (x > 5)
[Link]("Big");
}
}

A) Big​
B) Small​
C) 10​


D) Error​
Answer: A) Big

77. Output:
class A {
public static void main(String args[]) {
int x = 0;
while (x < 3) {
[Link](x);
x++;
}
}
}

A) 012​
B) 123​
C) 01​


D) Infinite​
Answer: A) 012

78. Output:
class A {
public static void main(String args[]) {
for (int i=1; i<=3; i++) {
if (i==2) continue;
[Link](i);
}
}
}

A) 13​
B) 12​
C) 123​


D) 2​
Answer: A) 13

79. Output:
class A {
public static void main(String args[]) {
int x = 5;
[Link](x == 5 && x < 10);
}
}

A) true​
B) false​
C) Error​


D) 0​
Answer: A) true

80. Output:
class A {
public static void main(String args[]) {
int a = 5;
[Link](a == 10 ? "Yes" : "No");
}
}

A) No​
B) Yes​
C) 5​

D) Error​
Answer: A) No

81. Output:
class A {
public static void main(String args[]) {
String s = "Java";
[Link]([Link](1));
}
}

A) a​
B) J​
C) v​


D) Error​
Answer: A) a

82. Output:
class A {
public static void main(String args[]) {
int[] arr = {1,2,3};
[Link](arr[1]);
}
}

A) 2​
B) 1​
C) 3​


D) Error​
Answer: A) 2

83. Output:
class A {
public static void main(String args[]) {
int[] arr = {1,2,3};
[Link]([Link]);
}
}

A) 3​
B) 2​
C) 4​


D) Error​
Answer: A) 3

84. Output:
class A {
public static void main(String args[]) {
[Link](10 % 3);
}
}

A) 1​
B) 3​
C) 10​


D) 0​
Answer: A) 1

85. Output:
class A {
public static void main(String args[]) {
int a = 10;
int b = a++;
[Link](b);
}
}

A) 10​
B) 11​
C) Error​


D) 9​
Answer: A) 10

87. Output:
class A {
public static void main(String args[]) {
int a = 5;
int b = 2;
[Link](a / (double)b);
}
}

A) 2.5​
B) 2​
C) 2.0​


D) Error​
Answer: A) 2.5

88. Output:
class A {
public static void main(String args[]) {
String s1 = "Java";
String s2 = "java";
[Link]([Link](s2));
}
}

A) true​
B) false​
C) Error​


D) 1​
Answer: B) false​
(String comparison in Java is case-sensitive)
89. Output:
class A {
public static void main(String args[]) {
String s1 = "Java";
String s2 = "Java";
[Link](s1 == s2);
}
}

A) true​
B) false​
C) Error​


D) Null​
Answer: A) true​
(String literals share the same memory reference in Java String Pool)

90. Output:
class A {
public static void main(String args[]) {
for(int i=1; i<=3; i++){
for(int j=1; j<=i; j++){
[Link]("*");
}
[Link]();
}
}
}

A)

*
**
***

B) ***​
C) *​

D) **​
Answer: A)

*
**
***

91. Output:
class A {
public static void main(String args[]) {
int sum = 0;
for(int i=1; i<=3; i++){
sum += i;
}
[Link](sum);
}
}

A) 6​
B) 3​
C) 5​


D) 4​
Answer: A) 6

92. Output:
class A {
public static void main(String args[]) {
int x = 10;
if (x > 10)
[Link]("A");
else if (x == 10)
[Link]("B");
else
[Link]("C");
}
}
A) A​
B) B​
C) C​


D) Error​
Answer: B) B

93. Output:
class A {
public static void main(String args[]) {
int arr[] = {10, 20, 30};
for (int i : arr)
[Link](i + " ");
}
}

A) 10 20 30​
B) 10 30 20​
C) 20 10 30​


D) Error​
Answer: A) 10 20 30

94. Output:
a = [1, 2, 3]
[Link](4)
print(a)

A) [1, 2, 3, 4]​
B) [1, 2, 3]​
C) [4, 1, 2, 3]​


D) Error​
Answer: A) [1, 2, 3, 4]

95. Output:
a = [1, 2, 3, 4]
[Link]()
print(a)

A) [1, 2, 3]​
B) [2, 3, 4]​
C) [4, 3, 2]​


D) Error​
Answer: A) [1, 2, 3]

96. Output:
a = [10, 20, 30]
print(sum(a))

A) 60​
B) 30​
C) 20​


D) Error​
Answer: A) 60

97. Output:
s = "python"
print([Link]())

A) PYTHON​
B) python​
C) Error​


D) None​
Answer: A) PYTHON

98. Output:
s = "HELLO"
print([Link]())
A) hello​
B) HELLO​
C) Error​


D) None​
Answer: A) hello

99. Output:
for i in range(1,4):
print(i * "*")

A)

*
**
***

B) ***​
C) Error​


D) * * *​
Answer: A)

*
**
***

100. Output:
def factorial(n):
if n == 1:
return 1
else:
return n * factorial(n-1)

print(factorial(4))
A) 24​
B) 12​
C) 4​


D) 6​
Answer: A) 24

You might also like