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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:28:07+00:00 2026-05-20T18:28:07+00:00

Why does, for example, the result of operation between an unsigned short and int

  • 0

Why does, for example, the result of operation between an unsigned short and int always yields an int?

unsigned short s = 65535;
int i = 65535

Expression typeid(s * i * i).name(), gives a value which is out of the range of an int but still the implicit conversion returns an int, why?

  • 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-20T18:28:07+00:00Added an answer on May 20, 2026 at 6:28 pm

    There are a set of conversions called the usual arithmetic conversions that are used prior to the evaluation of most arithmetic operators.

    Basically, you can consider there to be a few rules for arithmetic on integers:

    • First, integer arithmetic is never performed with operands “smaller than” int, so in the case of short * signed char, both the short and the signed char operands are promoted to int, the two int values are multiplied, and then the result is an int.

    • Second, if one or both of the types are “larger than” int, the compiler selects a type that is at least “as large” as the type of the largest operand. So, if you have long * int, the int is promoted to a long and the result is a long.

    • Third, if either operand is unsigned, then the result is unsigned. So, if you have long * unsigned int, the long and the unsigned int are both promoted to an unsigned long and the result is an unsigned long.

    If either operand has floating point type, then floating point arithmetic is performed: float, double, or long double is used (which one depends on the types of the operands; the full table used to determine the result type can be found on the page linked at the beginning of this answer).

    Note that the result type is not dependent upon the values of the operands. The type has to be selected by the compiler at compile time, before the values are known.

    If the result of s * i * i is out of range of the result type (int, in your scenario), then you’re out of luck: your program can’t decide at runtime, “oh, I should switch to use a long!” because the result type had to be selected at compile time.

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

Sidebar

Related Questions

For example, does an operator exist to handle this? float Result, Number1, Number2; Number1
In this example from the App Engine docs , why does the example declare
I'm trying something like this, but this example does not work. jsObj = {};
Why does: const char example; (uint64*)example have a value of 140734799798420 and *(uint64*)example have
Please can some one briefly tell me with example what does the means of
Where can I find a RSA encrypt example that does not use NoPadding? --update
EDIT I isolated a real minimal example which does not work (it is a
What is the meaning of (char)0 . For example what does this mean? array[1]
Does anyone have an example of setting up Authlogic with a namespace in Rails?
Does anyone know good example of using CSS to create rounded corner box where:

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.