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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:05:42+00:00 2026-06-06T17:05:42+00:00

I tried the below, and it seems that ‘test’ results in wrong value. 2500*2500*2500

  • 0

I tried the below, and it seems that ‘test’ results in wrong value. 2500*2500*2500 == 15625000000, why the below operations result in different outcome?

unsigned long long int test = 2500*2500*2500;
fprintf(stderr, "*************** test = %lld, %llu\n", test, test);
unsigned long long int test2 = 15625000000;
fprintf(stderr, "*************** test2 = %lld, %llu\n", test2, test2);

Result:

*************** test = -1554869184, 18446744072154682432
*************** test2 = 15625000000, 15625000000
  • 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-06T17:05:44+00:00Added an answer on June 6, 2026 at 5:05 pm

    2500 * 2500 * 2500 is never promoted past int, so the signed overflow that occurs (which is, by the way, UB) stops the correct calculation from being performed.

    To allow it, you must tell the compiler that your literals are of a particular type. There are two ways to do this:

    1. By casting—casting a literal is generally handled at compile-time and has no runtime overhead:

      unsigned long long int test = (unsigned long long int)2500 * (unsigned long long int)2500 * (unsigned long long int)2500;
      

      Note that the cast is performed on the multiplicands individually. If the result of the operation were cast (e.g. (unsigned long long int)(2500 * 2500 * 2500)) then the cast would be too late to preserve the data.

    2. By suffixing:

      unsigned long long int test = 2500ULL * 2500ULL * 2500ULL;
      

      This is exactly as efficient at runtime as casting of literals is, but depending on usage may be easier or harder to read. Suffixing must be applied directly to a literal (it cannot be applied to the result of an operation, so (2500 * 2500 * 2500)ULL is illegal.)

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

Sidebar

Related Questions

The code below seems not to be inserting the parameter value to the query
I tried this dummy code below to test unnamed namespace. I have the following
EDIT: The problem with the below seems to be the bars label that is
I tried below code but as I run it gives a black screen image
i tried below javascript and it does open the url in open window but
I tried the below code to check whether my mobile is connected to a
I've tried the below script but I am getting an error: dim cn, rs
I want to send data through URL.I've tried the below code: Intent browserIntent =
I want to style mail body. I have tried the below methods to style
Can I set the attributedText property of a UILabel object? I tried the below

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.