Sail E0 Webinar

MCQs

Total Questions : 10
Question 1.

Evaluate the following
(false && true) || false || true


  1.    0
  2.    1
  3.    false
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> 1

None.


Question 2.


What is the value of p?


1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int p;
6.
bool a = true;
7.
bool b = false;
8.
int x = 10;
9.
int y = 5;
10.
p = ((x | y) + (a + b));
11.
cout << p;
12.
return 0;
13.
}
  1.    0
  2.    16
  3.    12
  4.    2
 Discuss Question
Answer: Option B. -> 16

None.


Question 3.


What is the output of the following program?


1.
#include
2.
using namespace std;
3.
int f(int p, int q)
4.
{
5.
if (p > q)
6.
return p;
7.
else
8.
return q;
9.
}
10.
main()
11.
{
12.
int a = 5, b = 10;
13.
int k;
14.
bool x = true;
15.
bool y = f(a, b);
16.
k =((a * b) + (x + y));
17.
cout
  1.    55
  2.    62
  3.    52
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> 52


Question 4.

Which of the two operators ++ and - work for the bool datatype in C++?


  1.    None
  2.    ++
  3.    -
  4.    Both
 Discuss Question
Answer: Option B. -> ++

Due to history of using integer values as booleans, if an integer is used as a boolean, then incrementing 

will mean that whatever its truth value before the operation, it will have a truth-value of true after it. 

However, it’s not possible to predict the result of — given knowledge only of the truth value of x, as 

it could result in false.


Question 5.

For what values of the expression is an if-statement block not executed?


  1.    0 and all negative values
  2.    0 and -1
  3.    0
  4.    0, all negative values, all positive values except 1
 Discuss Question
Answer: Option C. -> 0

The if-statement block is only not executed when the expression evaluates to 0. It’s just 

syntactic sugar for a branch-if-zero instruction.


Question 6.

Which of the following statements are false?


  1.    bool can have two values and can be used to express logical expressions.
  2.    bool cannot be used as the type of the result of the function.
  3.    bool can be converted into integers implicitly
  4.    a bool value can be used in arithemetic expressions.
 Discuss Question
Answer: Option B. -> bool cannot be used as the type of the result of the function.

None.


Question 7.


What is the value of the bool?


1.
bool is_int(789.54)
  1.    True
  2.    False
  3.    1
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> False

The given number is a double not an integer, so the function returns 0 which is boolean false.


Question 8.

Is bool a fundamental datatype in C++?


  1.    Yes
  2.    No, it is a typedef of unsigned char
  3.    No, it is an enum of {false,true}
  4.    No, it is expanded from macros
 Discuss Question
Answer: Option A. -> Yes

 C++ has bool as a fundamental data type.


Question 9.

Find the odd one out:


  1.    std::vector
  2.    std::vector short>
  3.    std::vector
  4.    std::vector
 Discuss Question
Answer: Option D. -> std::vector

std::vector<bool> is a specialized version of vector, which is used for elements of type 

bool and optimizes for space. It behaves like the unspecialized version of vector and the 

storage is not necessarily an array of bool values, but the library implementation may 

optimize storage so that each value is stored in a single bit.


Question 10.

What happens when a null pointer is converted into bool?


  1.    An error is flagged
  2.    bool value evaluates to true
  3.    bool value evaluates to false
  4.    the statement is ignored
 Discuss Question
Answer: Option C. -> bool value evaluates to false

A pointer can be implicitly converted to a bool. A nonzero pointer converts to true and zerovalued 

pointer converts to false.


Latest Videos

Latest Test Papers