If I don\'t assign a value to a variable when I declare it, does it default to zero or just whatever was previously in the memory?
e.g.
float x;
It depends on the lifetime of the variable. Variables with static lifetime are always zero-initialized before program start-up: zero-initialization for basic types, enum
s and pointers is the same as if you'd assigned 0
, appropriately converted to the type, to it. This occurs even if the variable has a constructor, before the constructor is called.