Class 7 Exam  >  Class 7 Tests  >  Test: C++ Booleans - Class 7 MCQ

Test: C++ Booleans - Class 7 MCQ


Test Description

10 Questions MCQ Test - Test: C++ Booleans

Test: C++ Booleans for Class 7 2024 is part of Class 7 preparation. The Test: C++ Booleans questions and answers have been prepared according to the Class 7 exam syllabus.The Test: C++ Booleans MCQs are made for Class 7 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: C++ Booleans below.
Solutions of Test: C++ Booleans questions in English are available as part of our course for Class 7 & Test: C++ Booleans solutions in Hindi for Class 7 course. Download more important topics, notes, lectures and mock test series for Class 7 Exam by signing up for free. Attempt Test: C++ Booleans | 10 questions in 10 minutes | Mock test for Class 7 preparation | Free important questions MCQ to study for Class 7 Exam | Download free PDF with solutions
Test: C++ Booleans - Question 1

Find the odd one out.

Detailed Solution for Test: C++ Booleans - Question 1

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.

Test: C++ Booleans - Question 2

What happens when a null pointer is converted into bool?

Detailed Solution for Test: C++ Booleans - Question 2

A pointer can be implicitly converted to a bool. A nonzero pointer converts to true and zero valued pointer converts to false.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: C++ Booleans - Question 3

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

Detailed Solution for Test: C++ Booleans - Question 3

The if-statement block is only not executed when the expression evaluates to 0. its just syntactic sugar for a branch-if-zero instruction.

Test: C++ Booleans - Question 4

What will be the output of the following C++ code?

    #include <iostream>
    using namespace std;
    int f(int p, int q)
    {
        if (p > q)
            return p;
        else
            return q;
    }
    main()
    {
        int a = 5, b = 10;
        int k;
        bool x = true;
        bool y = f(a, b);
        k =((a * b) + (x + y));
        cout << k;
    }

Detailed Solution for Test: C++ Booleans - Question 4

In this question, value of x = true and value of y will be also true as f(a,b) will return a non-zero value. Now when adding these values with integers, the implicit type conversion takes place hence converting both x and y to 1(integer equivalent of bool true value). So expression (a*b) + (x+y) is evaluated to 52.

Test: C++ Booleans - Question 5

Evaluate the following.

(false && true) || false || true

Detailed Solution for Test: C++ Booleans - Question 5

The given expression is equivalent to
[( false AND True) OR false OR true] This is OR or three values so if any of them will be true then the whole exp will be true and as we have last value as true so the answer of expression will be TRUE.

Test: C++ Booleans - Question 6

Is bool a fundamental data type in C++?

Detailed Solution for Test: C++ Booleans - Question 6

C++ has bool as a fundamental data type.

Test: C++ Booleans - Question 7

What is the value of the bool?

Detailed Solution for Test: C++ Booleans - Question 7

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

Test: C++ Booleans - Question 8

Which of the following statements are false?

Detailed Solution for Test: C++ Booleans - Question 8

Boolean can be used as a return value of a function.

Test: C++ Booleans - Question 9

Which of the two operators ++ and — work for the bool data type in C++?

Detailed Solution for Test: C++ Booleans - Question 9

Due to the 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 is not possible to predict the result of — given knowledge only of the truth value of x, as it could result in false.

Test: C++ Booleans - Question 10

What is the value of p in the following C++ code?

    #include <iostream>
    using namespace std;
    int main()
    {
        int p;
        bool a = true;
        bool b = false;
        int x = 10;
        int y = 5;
        p = ((x | y) + (a + b));
        cout << p;
        return 0;
    }

Detailed Solution for Test: C++ Booleans - Question 10

| means bitwise OR operation so x | y (0101 | 1010) will be evaluated to 1111 which is integer 15 and as a is true and b is false so a+b(1 + 0) = 1. So final value of expression in line #10 will be 15 + 1 = 16.

Information about Test: C++ Booleans Page
In this test you can find the Exam questions for Test: C++ Booleans solved & explained in the simplest way possible. Besides giving Questions and answers for Test: C++ Booleans, EduRev gives you an ample number of Online tests for practice

Top Courses for Class 7

Download as PDF

Top Courses for Class 7