Hi Debojit Acharjee,
I tested your code and got the same results as you, but when I tried to output 12345678901234566 and 12345678901234568, my compiler was able to display them correctly. The compiler I'm using is VS2022, I suggest you try it.
In C language, if you assign a number to a double variable, the compiler will do its best to represent it as a double. In some cases it may round to the nearest representable number, while in other cases it may choose a close representable number.
This behavior depends on the specification and implementation details of floating-point numbers, as well as compiler and hardware differences. Therefore, even the same code may give different results when run on different compilers or platforms.
Best regards,
Elya Yao
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.