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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:59:05+00:00 2026-05-21T03:59:05+00:00

I want to be better about knowing when I should cast. What are the

  • 0

I want to be better about knowing when I should cast. What are the implicit type conversion rules in C++ when adding, multiplying, etc. For example,

int + float = ?
int * float = ?
float * int = ?
int / float = ?
float / int = ?
int / int = ?
int ^ float = ?

et cetera…

Will the expression always be evaluated as the more precise type? Do the rules differ for Java?
Please correct me if I have worded this question inaccurately.

  • 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-21T03:59:06+00:00Added an answer on May 21, 2026 at 3:59 am

    In C++ operators (for POD types) always act on objects of the same type.
    Thus if they are not the same one will be promoted to match the other.
    The type of the result of the operation is the same as operands (after conversion).

    if:
    either is      long double       other is promoted >      long double
    either is           double       other is promoted >           double
    either is           float        other is promoted >           float
    either is long long unsigned int other is promoted > long long unsigned int
    either is long long          int other is promoted > long long          int
    either is long      unsigned int other is promoted > long      unsigned int
    either is long               int other is promoted > long               int
    either is           unsigned int other is promoted >           unsigned int
    either is                    int other is promoted >                    int
    
    Otherwise:
    both operands are promoted to int
    

    Note. The minimum size of operations is int. So short/char are promoted to int before the operation is done.

    In all your expressions the int is promoted to a float before the operation is performed. The result of the operation is a float.

    int + float =>  float + float = float
    int * float =>  float * float = float
    float * int =>  float * float = float
    int / float =>  float / float = float
    float / int =>  float / float = float
    int / int                     = int
    int ^ float =>  <compiler error>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about how to pivot/total (for want of a better word)
I want to better understand the capabilities and limitations of what can be done
what is the best free/open source WinForms progress bar control? (i.e. want a better
I have a .exe app which I want to understand better - I can
See here http://www.hanselman.com/blog/InSearchOfThePerfectMonospacedProgrammersFontInconsolata.aspx - for want of a better description - the statement block
I want to know that is there any better method to do : var
I want to know if there is a better way (than what I'm currently
I want to use some NSAssert stuff and other things to enable better debugging
I don't want to make this into a which is better... MVC or WebForms
I want to test some QAbstractListModels I already implemented, is it better to use

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.