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

前端 未结 7 522
被撕碎了的回忆
被撕碎了的回忆 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 04:57

    It's just considered good practice to initialise a variable with a literal constant of the same type. In this case you have a float variable and you should initialise it with a float literal constant, i.e. 0.0f, rather than an int (0) which is then implicitly cast to a float.

提交回复
热议问题