C ++: difference between 0. and 0.0?

I am well aware of the difference between 0and 0.0(int and double).

But is there a difference between 0.and 0.0(pay attention to.)?

Thank you very much in advance,

Axel

+3
source share
5 answers

There is no difference. Both literals are double. From C ++ - grammar:

fractional-constant:
    digit-sequenceopt . digit-sequence
    digit-sequence .

See: C ++ Hyperlink BNF Grammar

+7
source

No no.

+1
source

. , .0.

+1

. .

:

 cout << (5 / 2) << endl;
 cout << (5. / 2) << endl;
 cout << (5.0 / 2) << endl;

:

 2
 2.5
 2.5

You can see that the first line uses integer division (because both values are integers), while 5.and 5.0are both identified as types of floating-point, and so they call "normal division."

+1
source

0has an int type, but can be cast to double and 0.0has a double type, but can be sent to int.
Both casts are implicit.

-2
source

Source: https://habr.com/ru/post/1780181/


All Articles