zero divide

Can i assume that this have proper behavior:
1
2
3
4
5
const int NUM = 5;
for(int i = 0; i < NUM; ++i)
{
    float data = (float)i / (float)NUM;
}


or should i check if i is zero?
1
2
3
4
float data = 0.0f;
if(0 != i)
    data = (float)i / (float)NUM;
    

Last edited on
You are permitted to divide zero by anything you like. The first one is fine.
Yes. You can assume a correct behavior. But, I suggest you to keep variable declarations outside loops.
To increase readability of your code try to put all the declarations you need at the beginning of the body (main or functions). Enjoy programming.
Thank you both.
Topic archived. No new replies allowed.