What is the significance of 0.0f when initializing (in C)?

前端 未结 7 508
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 04:30

I\'ve seen code where people initialize float variables like this:

float num = 0.0f;

Is there a significant difference between this and jus

7条回答
  •  迷失自我
    2020-11-29 05:13

    Well, strictly speaking, 0 is an integer, so float num = 0 requires a casting from integer to float. But I suppose the compiler does this for you anyway. I guess people use 0.0f in order to emphasize that this is a float, so nobody mistakes it for an integer.

提交回复
热议问题