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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:45:36+00:00 2026-05-15T04:45:36+00:00

A little test program: #include <iostream> const float TEST_FLOAT = 1/60; const float TEST_A

  • 0

A little test program:

#include <iostream>


const float TEST_FLOAT = 1/60;

const float TEST_A = 1;
const float TEST_B = 60;
const float TEST_C = TEST_A / TEST_B;

int main()
{
 std::cout << TEST_FLOAT << std::endl;
 std::cout << TEST_C << std::endl;

 std::cin.ignore();
 return 0;
}

Result :

0
0.0166667

Tested on Visual Studio 2008 & 2010.

  1. I worked on other compilers that, if I remember well, made the first result like the second result. Now my memory could be wrong, but shouldn’t TEST_FLOAT have the same value than TEST_C? If not, why?
  2. Is TEST_C value resolved at compile time or at runtime? I always assumed the former but now that I see those results I have some doubts…
  • 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-15T04:45:37+00:00Added an answer on May 15, 2026 at 4:45 am

    In

    1/60
    

    Both of the operands are integers, so integer arithmetic is performed. To perform floating point arithmetic, at least one of the operands needs to have a floating point type. For example, any of the following would perform floating point division:

    1.0/60
    1.0/60.0
    1/60.0
    

    (You might choose to use 1.0f instead, to avoid any precision reduction warnings; 1.0 has type double, while 1.0f has type float)

    Shouldn’t TEST_FLOAT have the same value than TEST_C?

    In the TEST_FLOAT case, integer division is performed and then the result of the integer division is converted to float in the assignment.

    In the TEST_C case, the integer literals 1 and 60 are converted to float when they are assigned to TEST_A and TEST_B; then floating-point division is performed on those floats and the result is assigned to TEST_C.

    Is TEST_C value resolved at compile time or at runtime?

    It depends on the compiler; either method would be standards-conforming.

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

Sidebar

Related Questions

Here is a little test program: #include <iostream> class Test { public: static void
What's wrong with the following little program that passes a function object? #include <iostream>
This question might be a little specific but the test program im writing uses
I'm having trouble building a little program that uses Boost.Test on my Mac with
I'm trying to compile a simple little test program. and I'm getting errors: MacBook-Air:Untitled
My little test program that I got out of the Official MCTS EXAM 70-562
The little test program below prints out: And SS Number IS =3039 I would
I wrote a little test program to show here. Here is the source code.
I'm writing a little test program where I can look at all the notifications
I am writing a little test program, and I have a problem regarding the

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.