I compiled a program in objective C.
int a = 3; a = (a++) * (a++); NSLog(@"a= %d",a);
Return the output:
a=11
Whereas in c# the output is 12.
Can anyone explain me the difference in the behaviour of ++ operator in objective C?
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.
There’s no difference in the
++operator. The problem is you’re invoking undefined behavior. Specifically, you’re reading and updating theavariable twice within the same sequence point, which is explicitly undefined in the ANSI C spec. The value you get from that expression may differ from compiler to compiler, it may even differ between versions of the same compiler, or even between invocations of the same compiler version with separate optimizations turned on.