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

y = − x + 1 y=−x+1 2 x − y = 2 2x−y=2
A student is doing an investigation into the masses of different materials of different densities. A cube has edges of length 1.5 cm and a density of 3500 kg/m²
What is the definition of the "Marketing Mix" ?
What is the characteristics of the logarithm 418000
Scenario 2: You are completing an online application for a position in project management. In the application, you are asked to state your specific experience w
Then _______ went back anxious / To return while Beowulf was alive, to bring him / Treasure they's won together. He ran, / Hoping his wounded king, weak / And d
please, need help with this, IT'S URGENT!!
Please help with this exercise: Consider the vectors v1, v2, v3 in R2 (sketched in the accompanying figure). Vectors v1 and v2 are parallel. How many solutions
What is a satirist goal ?
21 Q please in the picture