+ 3

Explain the output...

Initially i=4 Evaluate j if j=++i*i++

22nd Nov 2018, 11:21 AM
Paras Dandwani
Paras Dandwani - avatar
2 Respuestas
+ 15
output will be 30 In C : ●precedence of postfix x++ is more than prefix ++x ●associativity of postfix is from Left to Right & opposite for prefix [in above problem , game is of precedence , as associativity comes in picture when multiple operators of same precedence are there in single expression] //have a look at this image to get little idea of associativity also : https://goo.gl/images/ivzxy7 //here is the code for confirmation #include <stdio.h> int main() { int i=4,j=++i*i++; printf("%d",j); return 0; }
22nd Nov 2018, 11:53 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 15
~ swim ~ Yes, sorry for the mistake there, I learned about undefined behavior there after 1 more post where I tried to use same associativity & precedence logic but things didn't appear to work good, but forgot to edit here. //Things not go same everywhere like they go in Java. I will take care.
11th Mar 2019, 10:03 PM
Gaurav Agrawal
Gaurav Agrawal - avatar