LearnFrenzy
Sign in Take a free test

std::string · Predict the Output · Question 14

s += 65 vs s += "65" Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 14 Back to Exercise

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

main.cpp
#include <iostream>
#include <string>

int main() {
    std::string a = "x", b = "x", c = "x";
    a += 65;
    b += "65";
    c += std::to_string(65);
    std::cout << a << ' ' << b << ' ' << c << ' ' << a.size() << b.size() << '\n';
    return 0;
}
  • A xA x65 x65 23 Correct
  • B x65 x65 x65 33
  • C xA xA x65 22
  • D x65 x65 xA 33
Correct Answer: Option A

The int 65 converts to the char 'A' and is appended as one character. "65" and to_string(65) append the two digit characters.

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