MCQ Bank
What will be the output of following C++ program? #include <iostream> using namespace std; int main() { int num1 = 10; int num2 = 20/3; int sum; sum = num1 + num2; cout << "The sum is: " << sum << endl; return 0; }
- A) The sum is: 19
- B) The sum is: 16
- C) The sum is: 18
- D) The sum is: 20
In C/C++, which of the following data type is used to store real numbers?
- A) int
- B) float
- C) char
- D) boolean
Which of the following is an example of logical operator?
- A) &&,||
- B) <,>
- C) +,*
- D) /,%
Suppose we have an integer variable named “num” with 4567 as its value, then what will be the resulting value for the expression “num/100”?
- A) 45
- B) 4
- C) 456
- D) 456.7
What will be the output of the following code? int x = 15; int y = 10; int z = 5; cout << x * x - 4 * y * z;
- A) -25
- B) 5
- C) 25
- D) -5
Learning “how to program” is important, because it develops _______ and problem-solving abilities.
- A) Listening
- B) Reading
- C) Writing
- D) Analytical
What will be the output of the following code? int i = 0; while(i!=15){ cout << i << " "; i = i + 5; }
- A) 5 10
- B) 1 5 10
- C) 0 5 10
- D) 0 5
If the condition is not made false in while loop, what will happen?
- A) Loop will become infinite.
- B) Program will terminate early.
- C) Program will not run at all.
- D) Syntax errors occur.
Which of the following structure is correct for WHILE loop?
- A) While (start; condition)
- B) While (condition)
- C) While (condition; end)
- D) While (start; condition; end)
Which of the following is true about the switch statement?
- A) It is valid for the small programs only.
- B) It is valid for the large programs only.
- C) It works efficiently on compound conditions which use logical operators.
- D) It cannot handle the compound conditions which use logical operators.
The loop, given below, will iterate_____ times. For (int counter = 1; counter < 10; counter = counter +1)
- A) 10
- B) 0
- C) 9
- D) 110
In following switch statement program with two cases and an expression in the switch condition, what will be the output of the program? #include <iostream> using namespace std; int main() { int num = 7; switch(num % 2) { case 0: cout << "Even number" << endl; break; case 1: cout << "Odd number" << endl; break; default: cout << "Invalid number" << endl; } return 0; }
- A) Compile-time error
- B) Invalid number
- C) Even number
- D) Odd number
What will be the output of following program? #include <iostream> using namespace std; int main() { int x = 5; cout << x++ << " " << --x << " " << ++x << endl; return 0; }
- A) 5 6 7
- B) 6 5 6
- C) 4 5 6
- D) 5 5 6
If a function does not return anything, its return type will be ______.
- A) Null
- B) Zero
- C) Return 0
- D) Void
Which of the following is the first step in FOR loop?
- A) Initialization condition
- B) Termination condition
- C) Continuation condition
- D) Incrementing condition
What will be the output of the following code? int i = 1; while(i<10){ if (i / 2 == 2) cout << i << “ ”; i++; }
- A) 4 5
- B) 2 3
- C) 2 4
- D) 6 7
What will be the output of the following piece of code? int square(int number) { int result = 0; result = number * number; return result; } int main() { cout<<square(9); }
- A) 99
- B) 99
- C) 81
- D) 49
The operators ++ and -- are used to increment or decrement the variable value by ______.
- A) 1
- B) 4
- C) 3
- D) 2
Which of the following is an example of repetition structure?
- A) while
- B) cond
- C) if-else
- D) if
While programming in C++, the statement if (x = 3), will result into a ______.
- A) Syntax Error
- B) Runtime Error
- C) Linker Error
- D) Logical Error