LearnFrenzy
Sign in Take a free test

Input/Output with cin and cout · Predict the Output · Question 6

showpos and boolalpha output Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

What is the output of the following C++ program?

main.cpp
#include <iostream>

int main() {
    std::cout << std::showpos << 5 << ' ' << 0 << ' ' << -5 << std::noshowpos << ' ';
    std::cout << (3 < 2) << ' ' << std::boolalpha << (3 < 2) << '\n';
    return 0;
}
  • A +5 +0 -5 0 false Correct
  • B +5 0 -5 0 false
  • C 5 0 -5 false false
  • D +5 +0 -5 false false
Correct Answer: Option A

showpos adds + to non-negative numbers, including zero. bool prints as 0 until boolalpha is set.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links