LearnFrenzy
Sign in Take a free test

std::string · Predict the Output · Question 17

Converting to upper case with std::transform Answer, explanation & discussion

  • Output
  • Medium
  • 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 <algorithm>
#include <cctype>
#include <iostream>
#include <string>

int main() {
    std::string s = "c++ is Fun 2026!";
    std::string up = s;
    std::transform(up.begin(), up.end(), up.begin(),
                   [](unsigned char c) { return static_cast<char>(std::toupper(c)); });
    std::cout << up << " | " << s << '\n';
    return 0;
}
  • A C++ IS FUN 2026! | c++ is Fun 2026! Correct
  • B C++ IS FUN 2026! | C++ IS FUN 2026!
  • C c++ IS FUN 2026! | c++ is Fun 2026!
  • D C++ Is Fun 2026! | c++ is Fun 2026!
Correct Answer: Option A

toupper changes only lowercase letters; digits and symbols stay. up is a copy, so s is unchanged.

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