LearnFrenzy
Sign in Take a free test

Modern C++ Features (C++11 to C++23) · Predict the Output · Question 17

Digit separators and binary literals Answer, explanation & discussion

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

What is the output of the following C++ program on a 64-bit system?

main.cpp
#include <iostream>

int main() {
    long long population = 1'428'627'663;
    int mask = 0b1111'0000;
    int hex = 0xFF'FF;
    double precise = 3.141'592;
    std::cout << population / 1'000'000 << ' ' << mask << ' ' << hex << ' ' << precise << '\n';
    return 0;
}
  • A 1428 240 65535 3.14159 Correct
  • B 1428 11110000 65535 3.141'592
  • C 1428627663 240 65535 3.14159
  • D 1428 240 255 3.14159
Correct Answer: Option A

The ' separators (C++14) are ignored by the compiler. 0b1111'0000 is 240; cout prints doubles with 6 significant digits.

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