LearnFrenzy
Sign in Take a free test

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

std::hex stays active until std::dec Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 Back to Exercise

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

main.cpp
#include <iostream>

int main() {
    std::cout << std::hex << 10 << ' ' << 16 << ' ';
    std::cout << 255 << ' ' << std::dec << 255 << '\n';
    return 0;
}
  • A a 10 ff 255 Correct
  • B a 16 255 255
  • C a 10 255 255
  • D 10 16 ff 255
Correct Answer: Option A

Once std::hex is inserted, every integer is printed in hex – even in the next statement – until std::dec switches back.

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