I’m new to C language so please sum1 help me out.
A C code written
int i=3;
printf("%d",++i + ++i);
Complier gives O/P =9. How?
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.
The results are undefined. You’re modifying a variable more than once in an expression (or sequence point to be more accurate).
Modifying a variable more than once between sequence points is undefined, so don’t do it.
It might be your compiler, for this particular case decides to evalate
++i + ++ias++i, yielding 4, leaving i to be 4++i, yielding 5, leaving i to be 5 (as the prior step left i as 4, incrementing it to 5)Another compiler, or if you alter the optimization level, or if you change the code slightly, might produce different output.