Does the output of the code given below depends on the compiler or it is guaranteed to be same for all the compilers?
int main()
{
int i=5;
i=i/3;
printf("%d\n",i);
return 0;
}
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.
Yes, the behaviour of your example is well-defined.
However, in the case of negative values, it is less clear. Pre-C99, whether integer division was rounded towards zero or towards negative infinity was left as implementation-defined:
C99 mandates rounding towards zero: