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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:16:17+00:00 2026-06-02T13:16:17+00:00

This might be very basic but I got very curious what the reason is.

  • 0

This might be very basic but I got very curious what the reason is.

When dealing with different types of operations such as multiplication and division with data by different types (int, float etc) what decides which datatype that gets picked?

For example, if I do the following:

float a = 5 / 10;

I will get “0” as result since the 5 and the 10 are temporarily stored in an int where we do the division, and then we put it in a float. Right?

But if we instead do:

float a = (float)5 / 10;

We get 0.5 instead.

How does the decision making look when float is prefered over int in this case in C?

  • 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-02T13:16:18+00:00Added an answer on June 2, 2026 at 1:16 pm

    Take a look at this snippet.

    float a = 5 / 10;
    

    5 and 10 are represented as integers to C (and Java and C++ and Python 2.x) by default. They’re not specified to be stored in any other way; that is to say, they don’t match the appearance of a floating-point type. Integer division results in truncation, so you’ll get the value 0 every time.

    Now, regarding the second snippet:

    float a = (float)5 / 10;
    

    …C (or Java or C++ or Python 2.x) will interpret it as:

    float a = 5.0 / 10;
    

    Because the floating-point value is of a higher rank than an integer, it will promote the integer to a float. This is known as type promotion. You can read a bit about it here.

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

Sidebar

Related Questions

This might be pretty basic, but was very curious to know. Here's the code
I know, this might be a very basic question but I am not 100%
this might be a very very basic question, but what is the best way
This might be a very basic question, but I'm getting a bit confused. I'm
This might be very basic question to some but I am struggling for quite
This might be a very basic question, but I am a bit confused about
This might be a very basic and clueless question, but while I understand that
This might be a very basic question, but have not found a convincing answer
this is might be a very basic question, but seems like it's not easy
This might sound very very basic 101 type question, but I really need help

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.