alexy0675 alexy0675
  • 02-06-2018
  • Computers and Technology
contestada

I'm doing C++. When i multiply 200000 by 200000, i get 1345294336. I wrote
long long x = 200000 * 200000
cout << x << endl;

Respuesta :

tonb
tonb tonb
  • 04-06-2018
Even though your variable x is large enough to hold the answer 40000000000, the constants 200000 are treated as integers, such that the multiplication is first fitted in an integer that is too small.

The solution is to use the 'LL' suffix on the constants, so that the compiler knows to treat them as long longs from the start:

long long x = 200000LL * 200000LL;

The number 1345294336 can be explained by ANDing 40000000000 with 0xFFFFFFFF (which is the maximum size of an unsigned long)
Answer Link

Otras preguntas

What is a sculpture series? What elements does the artist need to consider when creating a sculpture series?
Explain how a dense substance, such as metal, is able to float on a less dense substance, like water. Please Help! Remember you will get rewards!!!
-5(11-3t) = -6t - 4 what does t equal?
If bacteria divide every 30 min, and you start with a single bacterium at noon, how many bacteria will you have just after 2:00 pm?
If the hydrogen ion concentration is 10-10m what is the ph of the solution
PLS SOLVE THIS!!`1/2p + 7= 3/4p + 9
What would the value of “c” need to be to make this a perfect square trinomial? x^2-38x+c 38 76 361 - 76
Does a star's apparent brightness depend only on its distance from earth?
Who determined that the military authorities had the power to segregate all citizens of Japanese descent from the West Coast?
which of the following greek thinkers discovered the value of pi