size = (size_in_bytes + sizeof(int) - 1) / sizeof(int);
This is more of a math questions than real programming question…
Is it because C always round down?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Integer division truncates in C, yes. (i.e. it’s round towards zero, not round down.)
By adding “divisor – 1” you make sure that any number which isn’t an exact multiple of the divisor gets rounded up. So for example, dividing by 3:
etc