Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7682763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:38:37+00:00 2026-05-31T18:38:37+00:00

cout << boolalpha (1 < 0) << endl; I was compiling this recently as

  • 0
cout << boolalpha ("1" < "0") << endl;

I was compiling this recently as a spin off from some course work I was doing. Why does this produce true when I execute it?

cout << boolalpha (string("1") < string("0")) << endl;

does the comparison as expected.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:38:39+00:00Added an answer on May 31, 2026 at 6:38 pm

    It’s comparing const char*, the result of "1" and "0" is undefined by the standard, whereas the comparison of 2 std::strings is defined and your output in that case is expected.

    Quick case in point:

    char* y = "0";
    char* x = "1";
    std::cout << (x<y) << endl;
        //output 1 on my platform
    

    and

    char* x = "1";
    char* y = "0";
    std::cout << (x<y) << endl;
        //output 0 on my platform
    

    I’m specifying “on my platform” because there’s no standard rule (but it can be a compiler rule) to where the pointers are created or in which order they are created.

    In my case, the addresses are assigned in reverse order of declaration.

    I’m willing to bet that if you run:

    cout << ("1" < "0") << endl;
    

    and

    cout << ("0" < "1") << endl;
    

    you’d get the same output (although it’s not a rule). Note that you should run them in different instances of the program. If you run them in the same instance, you might get different results, as string literals reside in a single place in memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class object { public: void check() { std::cout<<I am doing ok...<<std::endl; } }; int
class Base { public: virtual void func() const { cout<<This is constant base <<endl;
cout and the << operator work fine in compiling c++ program in CYgwin but
Possible Duplicate: Why does cout print char arrays differently from other arrays? If I
class Widget { public: Widget() { cout<<~Widget()<<endl; } ~Widget() { cout<<~Widget()<<endl; } void* operator
A simple test app: cout << new int[0] << endl; outputs: 0x876c0b8 So it
How can you get unbuffered output from cout, so that it instantly writes to
if(typeid(int) == typeid(const int)) cout << Same types<< endl; PROGRAM OUTPUT: Same types am
I just stumbled over the following line of code cout << &Blahh << endl;
I'm getting cin cout and endl as undeclared errors despite using #include <iostream> #include

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.