C Programming Increment and Decement Operaotr Proble -


$void main() { int a=10,c; c= ++a + ++a; printf("%d",c); } 

this program actuly print valu of c=24 calculation can should c=23 ,how possible

your program has bug -- modify same variable twice without intervening sequence point. fix bug , mystery go away.

a deep understanding of not how language works how compilers work required understand why buggy code happens happens do. suggest not writing buggy code and, when find bug, fix instead of trying understand precisely why , how broke.

my advice stop. learned right lesson -- code triggers undefined behavior unpredictable , doesn't might expect do. that's need know ub until you're expert @ using language correctly.


Comments

Popular posts from this blog

c++11 - Intel compiler and "cannot have an in-class initializer" when using constexpr -

rest - Spring boot: Request method 'PUT' not supported -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -