🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: C++ Introduction: all 10 questions

Quiz: C++ Introduction · Question 8 of 10

What does this print? (code)

What does this print?

#include <iostream>
using namespace std;
int main() {
    bool ok = 5;
    cout << ok << " " << boolalpha << (3 > 7) << "\n";
    return 0;
}
  1. A.5 false
  2. B.true 0
  3. C.1 false
  4. D.1 0
Answer & explanation

Correct answer: 1 false

Any non-zero value becomes true, which prints as 1; after boolalpha, false prints as the word false.

Can you get the rest right without peeking?

Take the timed Quiz: C++ Introduction quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →