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 8733649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:41:37+00:00 2026-06-13T09:41:37+00:00

We all know C++ (while not a superset) is pretty much derived from C.

  • 0

We all know C++ (while not a superset) is pretty much derived from C.

In C++, the operators <, <=, >, >=, ==, and != all have boolean return values.
However, in C, the same operators returned 1 or 0, since there was no ‘bool’ type in C.

Since all integer values except 0 are treated as “true”, and 0 is “false”, I want to know:

Does C++ still restrict the return values of the operators to be 1 vs 0, or does a ‘true’, from one of these operators, return any 1-byte value, so long as it isn’t 0?

I want to know since using these return values as explicit 1 or 0 would be useful in bitwise operations without branching.

As a terrible example, take the following:

bool timesTwo;
int value;

//...

if(timesTwo)
    value << 1;

//vs

value << (int) timesTwo;
  • 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-06-13T09:41:38+00:00Added an answer on June 13, 2026 at 9:41 am

    Does C++ still restrict the return values of the operators to be 1 vs 0, or does a ‘true’, from one of these operators, return any 1-byte value, so long as it isn’t 0?

    The comparison operators, assuming that they have not been overloaded, only ever return true and false.

    int(true) is always 1.

    int(false) is always 0.

    So,

    int one(1), two(2);
    assert( (one<two) == 1 );
    assert( (two<one) == 0 );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi all i want to know that while specifying url in my iphone native
We all know the effects that lots of thrown exceptions can have over the
As we all know social networks like Twitter, Facebook have their own mobile apps.
While we all know that x == y can be problematic, where x and
What is the easiest way to get all top level entry values from a
PHP, as we all know is very loosely typed. The language does not require
I have been using DDD for a while know so I am comfortable with
hi all i want to know that while we create a forigen key for
While answering this question I got a bit confused. We all know that this
As we all know, some Android phones have no Google services, such as HUAWEI,

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.