C++ Multiple Choice Questions
1. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 10; if (x > 5) cout << "Greater than 5" << endl; return 0; }
2. What is the result of the following code?
#include <iostream> using namespace std; int main() { int x = 4; if (x == 4) cout << "Equal to 4" << endl; return 0; }
3. How is an `else` statement used in C++?
4. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 3; if (x > 5) cout << "Greater than 5" << endl; else cout << "Not greater than 5" << endl; return 0; }
5. What is the result of the following code?
#include <iostream> using namespace std; int main() { int x = 7; if (x % 2 == 0) cout << "Even" << endl; else cout << "Odd" << endl; return 0; }
6. What is the output of the following code?
#include <iostream> using namespace std; int main() { int x = 5; int y = 10; if (x < y && x > 0) cout << "x is positive and less than y" << endl; return 0; }
7. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 6; if (x > 5) cout << "x is greater than 5" << endl; else if (x == 5) cout << "x is 5" << endl; else cout << "x is less than 5" << endl; return 0; }
8. What will the following code print?
#include <iostream> using namespace std; int main() { int a = 15; if (a % 3 == 0 || a % 5 == 0) cout << "Divisible by 3 or 5" << endl; return 0; }
9. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 10; if (x < 5) cout << "x is less than 5" << endl; else if (x < 15) cout << "x is between 5 and 15" << endl; else cout << "x is 15 or more" << endl; return 0; }
10. How does the `switch` statement differ from `if-else` in C++?
11. What will the following code print?
#include <iostream> using namespace std; int main() { int a = 8; if (a % 2 == 0 && a > 5) cout << "Even and greater than 5" << endl; return 0; }
12. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 4; int y = 7; if (x > 3 || y < 5) cout << "Condition met" << endl; return 0; }
13. What is the output of the following code?
#include <iostream> using namespace std; int main() { int x = 10; int y = 10; if (x == y) cout << "Equal" << endl; return 0; }
14. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 5; if (x > 10) cout << "Greater" << endl; else if (x > 0) cout << "Positive" << endl; return 0; }
15. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 5; if (x != 5) cout << "Not 5" << endl; else cout << "Is 5" << endl; return 0; }
16. What is the result of the following code?
#include <iostream> using namespace std; int main() { int x = 8; if (x < 10 && x > 5) cout << "Between 6 and 9" << endl; return 0; }
17. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 10; if (x > 5) { if (x < 15) cout << "In range" << endl; } return 0; }
18. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 3; if (x == 3) { cout << "Three" << endl; } else if (x == 4) { cout << "Four" << endl; } else { cout << "Not Three or Four" << endl; } return 0; }
19. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 7; if (x % 2 == 1) cout << "Odd" << endl; else cout << "Even" << endl; return 0; }
20. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 5; int y = 4; cout << x % y << endl; return 0; }
21. What is the output of the following code?
#include <iostream> using namespace std; int main() { int a = 12; if (a % 4 == 0) cout << "Divisible by 4" << endl; return 0; }
22. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 15; if (x >= 10 && x < 20) cout << "In range" << endl; return 0; }
23. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 9; if (x % 2 == 0) cout << "Even" << endl; else cout << "Odd" << endl; return 0; }
24. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 20; if (x < 10) cout << "Less than 10" << endl; else if (x < 20) cout << "Between 10 and 19" << endl; else cout << "20 or more" << endl; return 0; }
25. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int a = 7; int b = 5; if (a > b) cout << "a is greater than b" << endl; return 0; }
26. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 8; if (x % 4 == 0) cout << "Divisible by 4" << endl; else cout << "Not divisible by 4" << endl; return 0; }
27. What is the result of the following code?
#include <iostream> using namespace std; int main() { int x = 5; int y = 2; cout << x / y << endl; return 0; }
28. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 5; if (x > 0) cout << "Positive" << endl; else cout << "Negative" << endl; return 0; }
29. What is the output of the following code?
#include <iostream> using namespace std; int main() { int x = 4; if (x % 2 == 0) cout << "Even" << endl; else cout << "Odd" << endl; return 0; }
30. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 3; if (x > 0 && x < 5) cout << "In range" << endl; return 0; }
31. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 11; if (x > 10) cout << "Greater than 10" << endl; return 0; }
32. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 2; if (x != 2) cout << "Not 2" << endl; else cout << "Is 2" << endl; return 0; }
33. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 12; if (x % 2 == 0 && x < 15) cout << "Even and less than 15" << endl; return 0; }
34. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 20; if (x < 30) { if (x > 10) cout << "Between 11 and 29" << endl; } return 0; }
35. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 7; if (x < 5 || x > 10) cout << "Out of range" << endl; else cout << "In range" << endl; return 0; }
36. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 10; if (x % 3 == 0) cout << "Divisible by 3" << endl; else cout << "Not divisible by 3" << endl; return 0; }
37. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 6; if (x % 2 == 0 && x % 3 == 0) cout << "Divisible by 2 and 3" << endl; return 0; }
38. What is the result of the following code?
#include <iostream> using namespace std; int main() { int x = 15; if (x % 5 == 0) cout << "Divisible by 5" << endl; else cout << "Not divisible by 5" << endl; return 0; }
39. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 10; if (x < 5) cout << "Less than 5" << endl; else if (x == 10) cout << "Equal to 10" << endl; else cout << "Other value" << endl; return 0; }
40. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 3; if (x < 2 || x > 5) cout << "Out of range" << endl; else cout << "In range" << endl; return 0; }
41. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = -1; if (x < 0) cout << "Negative" << endl; else cout << "Positive" << endl; return 0; }
42. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 25; if (x % 5 == 0) cout << "Divisible by 5" << endl; else cout << "Not divisible by 5" << endl; return 0; }
43. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 14; if (x % 7 == 0) cout << "Divisible by 7" << endl; else cout << "Not divisible by 7" << endl; return 0; }
44. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 9; if (x < 10) cout << "Less than 10" << endl; else if (x == 10) cout << "Equal to 10" << endl; else cout << "Greater than 10" << endl; return 0; }
45. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 0; if (x == 0) cout << "Zero" << endl; else cout << "Non-zero" << endl; return 0; }
46. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = -5; if (x <= 0) cout << "Non-positive" << endl; else cout << "Positive" << endl; return 0; }
47. What is the output of the following code?
#include <iostream> using namespace std; int main() { int x = 8; if (x % 2 == 1) cout << "Odd" << endl; else cout << "Even" << endl; return 0; }
48. What is the result of the following code?
#include <iostream> using namespace std; int main() { int x = 20; if (x % 4 == 0 && x % 5 == 0) cout << "Divisible by 4 and 5" << endl; else cout << "Not divisible by 4 and 5" << endl; return 0; }
49. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 18; if (x > 20 || x < 10) cout << "Out of range" << endl; else cout << "In range" << endl; return 0; }
50. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 13; if (x % 2 == 1 && x % 3 == 0) cout << "Odd and divisible by 3" << endl; else cout << "Not odd and divisible by 3" << endl; return 0; }
51. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 17; if (x > 15) cout << "Greater than 15" << endl; else cout << "15 or less" << endl; return 0; }
52. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 10; if (x > 5 && x < 15) cout << "In range" << endl; else cout << "Out of range" << endl; return 0; }
53. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 0; if (x > 0) cout << "Positive" << endl; else if (x < 0) cout << "Negative" << endl; else cout << "Zero" << endl; return 0; }
54. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 15; if (x % 5 == 0 && x % 3 == 0) cout << "Divisible by 3 and 5" << endl; else cout << "Not divisible by 3 and 5" << endl; return 0; }
55. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 25; if (x % 10 == 0) cout << "Divisible by 10" << endl; else cout << "Not divisible by 10" << endl; return 0; }
56. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 7; if (x % 2 == 0) cout << "Even" << endl; else cout << "Odd" << endl; return 0; }
57. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 0; if (x > 0 && x % 2 == 0) cout << "Positive even" << endl; else if (x < 0 && x % 2 == 0) cout << "Negative even" << endl; else if (x == 0) cout << "Zero" << endl; else cout << "Non-zero odd" << endl; return 0; }
58. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 4; if (x % 2 == 0) cout << "Even" << endl; else cout << "Odd" << endl; return 0; }
59. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 30; if (x % 2 == 0 && x % 3 == 0 && x % 5 == 0) cout << "Divisible by 2, 3, and 5" << endl; else cout << "Not divisible by 2, 3, and 5" << endl; return 0; }
60. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 12; if (x % 4 == 0 || x % 6 == 0) cout << "Divisible by 4 or 6" << endl; else cout << "Not divisible by 4 or 6" << endl; return 0; }
61. What will the following code print?
#include <iostream> using namespace std; int main() { int x = 8; if (x % 2 == 0 && x > 5) cout << "Even and greater than 5" << endl; else cout << "Other" << endl; return 0; }
62. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 9; if (x % 3 == 0 || x % 5 == 0) cout << "Divisible by 3 or 5" << endl; else cout << "Not divisible by 3 or 5" << endl; return 0; }
63. What will the following code print?
#include <iostream> using namespace std; int main() { int x = 10; if (x > 5 && x < 15) cout << "In range" << endl; else cout << "Out of range" << endl; return 0; }
64. What will the output of the following code be?
#include <iostream> using namespace std; int main() { int x = 0; if (x == 0) cout << "Zero" << endl; else cout << "Non-zero" << endl; return 0; }
65. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 3; if (x % 2 == 0 || x % 3 == 0) cout << "Divisible by 2 or 3" << endl; else cout << "Not divisible by 2 or 3" << endl; return 0; }
66. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 25; if (x % 5 == 0 && x % 7 == 0) cout << "Divisible by 5 and 7" << endl; else cout << "Not divisible by 5 and 7" << endl; return 0; }
67. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 22; if (x % 2 == 0 && x > 20) cout << "Even and greater than 20" << endl; else cout << "Other" << endl; return 0; }
68. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 45; if (x % 9 == 0 && x % 5 == 0) cout << "Divisible by 9 and 5" << endl; else cout << "Not divisible by 9 and 5" << endl; return 0; }
69. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = -1; if (x < 0) cout << "Negative" << endl; else if (x == 0) cout << "Zero" << endl; else cout << "Positive" << endl; return 0; }
70. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 18; if (x % 3 == 0 && x % 4 != 0) cout << "Divisible by 3 but not 4" << endl; else cout << "Other" << endl; return 0; }
71. What will the output of the following code be?
#include <iostream> using namespace std; int main() { int x = 50; if (x % 2 == 0 && x % 5 == 0) cout << "Divisible by 2 and 5" << endl; else cout << "Not divisible by 2 and 5" << endl; return 0; }
72. What will the result of the following code be?
#include <iostream> using namespace std; int main() { int x = 14; if (x % 7 == 0 || x % 2 == 0) cout << "Divisible by 7 or 2" << endl; else cout << "Not divisible by 7 or 2" << endl; return 0; }
73. What will the output of the following code be?
#include <iostream> using namespace std; int main() { int x = 17; if (x % 2 == 0 && x % 5 == 0) cout << "Divisible by 2 and 5" << endl; else if (x % 2 == 0) cout << "Divisible by 2" << endl; else if (x % 5 == 0) cout << "Divisible by 5" << endl; else cout << "Not divisible by 2 or 5" << endl; return 0; }
74. What will the output of the following code be?
#include <iostream> using namespace std; int main() { int x = 6; if (x % 2 == 0 && x % 3 == 0) cout << "Divisible by 2 and 3" << endl; else if (x % 2 == 0) cout << "Divisible by 2" << endl; else if (x % 3 == 0) cout << "Divisible by 3" << endl; else cout << "Not divisible by 2 or 3" << endl; return 0; }
75. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 21; if (x % 7 == 0 && x % 3 == 0) cout << "Divisible by 7 and 3" << endl; else cout << "Not divisible by 7 and 3" << endl; return 0; }
76. What will the output of the following code be?
#include <iostream> using namespace std; int main() { int x = 8; if (x % 4 == 0 || x % 2 != 0) cout << "Divisible by 4 or not divisible by 2" << endl; else cout << "Other" << endl; return 0; }
77. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 30; if (x % 10 == 0 && x % 5 == 0) cout << "Divisible by 10 and 5" << endl; else cout << "Not divisible by 10 and 5" << endl; return 0; }
78. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 11; if (x % 3 != 0 || x % 2 != 0) cout << "Not divisible by 3 or 2" << endl; else cout << "Divisible by 3 and 2" << endl; return 0; }
79. What will the output of the following code be?
#include <iostream> using namespace std; int main() { int x = 13; if (x % 2 == 0) cout << "Even" << endl; else if (x % 2 != 0) cout << "Odd" << endl; else cout << "Neither" << endl; return 0; }
80. What will the result of the following code be?
#include <iostream> using namespace std; int main() { int x = 50; if (x % 4 == 0 && x % 5 == 0) cout << "Divisible by 4 and 5" << endl; else cout << "Not divisible by 4 and 5" << endl; return 0; }
81. What will the output of the following code be?
#include <iostream> using namespace std; int main() { int x = 8; if (x % 2 == 0 && x % 4 == 0) cout << "Divisible by 2 and 4" << endl; else cout << "Not divisible by 2 and 4" << endl; return 0; }
82. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 35; if (x % 7 == 0 && x % 5 != 0) cout << "Divisible by 7 but not 5" << endl; else cout << "Other" << endl; return 0; }
83. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 22; if (x % 2 == 0 || x % 5 == 0) cout << "Divisible by 2 or 5" << endl; else cout << "Not divisible by 2 or 5" << endl; return 0; }
84. What will the output of the following code be?
#include <iostream> using namespace std; int main() { int x = 9; if (x % 3 == 0 && x % 2 == 0) cout << "Divisible by 3 and 2" << endl; else if (x % 3 == 0) cout << "Divisible by 3" << endl; else if (x % 2 == 0) cout << "Divisible by 2" << endl; else cout << "Not divisible by 3 or 2" << endl; return 0; }
85. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 40; if (x % 8 == 0 || x % 5 == 0) cout << "Divisible by 8 or 5" << endl; else cout << "Not divisible by 8 or 5" << endl; return 0; }
86. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 7; if (x % 2 != 0 && x % 7 == 0) cout << "Divisible by 7 but not by 2" << endl; else cout << "Not divisible by 7 or by 2" << endl; return 0; }
87. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 12; if (x % 4 == 0 && x % 6 == 0) cout << "Divisible by 4 and 6" << endl; else cout << "Not divisible by 4 and 6" << endl; return 0; }
88. What will the output of the following code be?
#include <iostream> using namespace std; int main() { int x = 10; if (x % 2 == 0 && x % 5 != 0) cout << "Divisible by 2 but not 5" << endl; else if (x % 5 == 0) cout << "Divisible by 5" << endl; else cout << "Not divisible by 2 or 5" << endl; return 0; }
89. What will the output of the following code be?
#include <iostream> using namespace std; int main() { int x = 25; if (x % 5 == 0 && x % 7 == 0) cout << "Divisible by 5 and 7" << endl; else cout << "Not divisible by 5 and 7" << endl; return 0; }
90. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 14; if (x % 7 == 0 && x % 3 != 0) cout << "Divisible by 7 but not by 3" << endl; else cout << "Other" << endl; return 0; }
91. What will the output of the following code be?
#include <iostream> using namespace std; int main() { int x = 16; if (x % 4 == 0 && x % 8 != 0) cout << "Divisible by 4 but not by 8" << endl; else cout << "Other" << endl; return 0; }
92. What will the result of the following code be?
#include <iostream> using namespace std; int main() { int x = 18; if (x % 3 == 0 || x % 6 == 0) cout << "Divisible by 3 or 6" << endl; else cout << "Not divisible by 3 or 6" << endl; return 0; }
93. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 45; if (x % 5 == 0 && x % 9 == 0) cout << "Divisible by 5 and 9" << endl; else cout << "Not divisible by 5 and 9" << endl; return 0; }
94. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 28; if (x % 4 == 0 && x % 7 == 0) cout << "Divisible by 4 and 7" << endl; else cout << "Not divisible by 4 and 7" << endl; return 0; }
95. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 21; if (x % 3 == 0 && x % 7 == 0) cout << "Divisible by 3 and 7" << endl; else cout << "Not divisible by 3 and 7" << endl; return 0; }
96. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 40; if (x % 8 == 0 && x % 5 == 0) cout << "Divisible by 8 and 5" << endl; else cout << "Not divisible by 8 and 5" << endl; return 0; }
97. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 25; if (x % 2 == 0 && x % 5 == 0) cout << "Divisible by 2 and 5" << endl; else if (x % 2 == 0) cout << "Divisible by 2" << endl; else if (x % 5 == 0) cout << "Divisible by 5" << endl; else cout << "Not divisible by 2 or 5" << endl; return 0; }
98. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 27; if (x % 3 == 0 && x % 9 != 0) cout << "Divisible by 3 but not by 9" << endl; else cout << "Other" << endl; return 0; }
99. What will be the output of the following code?
#include <iostream> using namespace std; int main() { int x = 18; if (x % 2 == 0 && x % 3 == 0) cout << "Divisible by 2 and 3" << endl; else cout << "Not divisible by 2 and 3" << endl; return 0; }
100. What will be the result of the following code?
#include <iostream> using namespace std; int main() { int x = 30; if (x % 2 == 0 && x % 5 == 0) cout << "Divisible by 2 and 5" << endl; else if (x % 2 == 0) cout << "Divisible by 2" << endl; else if (x % 5 == 0) cout << "Divisible by 5" << endl; else cout << "Not divisible by 2 or 5" << endl; return 0; }
Thank You for Visiting!
We are deeply grateful for your time and attention. Your engagement with our content means a lot to us, and we hope that the information provided has been valuable and insightful for your C++ journey.
We strive to create resources that empower and inspire. If you found our content useful, please consider sharing it with others who might benefit from it. Your support helps us continue to provide quality content and make a difference in the programming community.
If you have any feedback, suggestions, or questions, we’d love to hear from you. Feel free to reach out through our contact page or leave a comment. Together, let's continue to learn and grow in the fascinating world of C++ programming!
Thank you once again for your visit. Keep coding and stay curious!