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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:23:01+00:00 2026-06-16T05:23:01+00:00

In C++ binary operators for intrinsic types, both operands should have the same type,

  • 0

In C++ binary operators for intrinsic types, both operands should have the same type, if not, one of the operands get converted to the other operand’s type based on a hierarchy:

long double
double
float
unsigned long long int
long long int
unsigned long int
long int
unsigned int
int

My Question is: Why unsigned T is in a higher level than T . is it just an arbitrary choice or there is some advantages in converting T to Unsigned T and not the other way around.

Update:

//where `unsigned int` to `int` work better.
int a=-3;
unsigned int b=3;
cout << a+b; /* this will output the right result if b get converted to int,
which is not what really happen.*/

//where `int` to `unsigned int` work better.
int a=3;
unsigned int b=pow(2,20);
cout << a+b; /* this will output the right result if a get converted to unsigned int,
which is fortunately what really happen.*/

So I dont see how convering T to Unsigned T has more advantages than the other way around.

  • 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-16T05:23:03+00:00Added an answer on June 16, 2026 at 5:23 am

    It is essentially an arbitrary choice that goes back to the early days of C.

    As far as I can determine, in pre-standard K&R C the rule basically was that if an operand of a operator had a unsigned type, then the result would also be unsigned (this is called unsigned-preserving).

    When C got standardized, this rule was changed to the rule currently used by both C and C++, which allows the unsigned property to get dropped, as long as the value can be represented in the target type (this is called value-preserving). The reason was that the new rules provide fewer surprises for the unsuspecting programmers when doing mixed signed/unsigned arithmetic.

    The conversion from T to unsigned T can have two interpretations:

    1. It is a hold-over from the old (unsigned preserving) rules.
    2. It is the only sane thing to do that does not require a type larger than unsigned long long for stuff like: 1ULL > -1LL, because the signed to unsigned conversion is always defined (by virtue of the wrap-around feature of unsigned integers), but the reverse conversion is not.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that array operators have the precedence. Then the binary arthimetic operators *
Php functions strcmp , strcasecmp and other from this family are binary-safe. Are operators
The binary you uploaded was invalid. The signature was invalid, or it was not
I have a Binary Search Tree, I use template to add any class object
Say we have a binary tree as follow: I'm looking for an algorithm to
I have a binary image that represents a number in MATLAB: I'd like to
I have been reading about bit operators in Objective-C in Kochan's book, Programming in
I am pretty new to bitwise operators. Let's say I have 3 variables a
I was perusing section 13.5 after refuting the notion that built-in operators do not
I'm trying to write an abstract class with some pure virtual binary operators, which

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.