c Language Suffix Question

Asked 1 years ago, Updated 1 years ago, 312 views

int main(void)

{

long long big;

big = 700000000 * 700000000;

printf("%lld",big);

return 0;

}

I don't know why I have to put the suffix ll after 700000000

c int

2022-10-13 01:00

1 Answers

The reason is that big = 7000000 * 7000000; is calculated once 7000000 * 700000000 is calculated and then substituted for big.

First, 700000000 *700000000 is calculated, and 700000000 is the int type and 7000000*700000000 is the multiplication of the int types, so the result is also int type.

However, since the actual calculation results go beyond the range of the int type, the final result obtained by the int type is obtained by truncating some of the actual values. This invalid value is eventually stored in big.

On the other hand, if 7000000LL * 7000000LL is specified in the first place, 7000000LL is long int type, and the multiplication result of the two long int types is long long int type. The result of 700000000LL *700000000LL is a value that exists within the long int type, so the value is obtained normally, and the value is stored in big.


2022-10-13 01:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.