Assign zero to float in C
问题 I've got in the habit of using float f = 0.; //with a trailing period when assigning a zero value to a float in C. Should I be using float f = 0.f; //with an explicit float size or just stop messing about and use float f = 0; //with no trailing anything? Where did I pick up that habit and why? Is any version more right or wrong than any other? 回答1: 0.0 and 0. are doubles, not floats. While it is legal to assign doubles to floats in C without an explicit cast, 0.0f or 0.f would be the correct