C operator -- gives two different results -


#import <stdio.h> int main() {     int a,d,b,c;     = 10;     c = 10;     d = --c + --c+1;      b = --a +1+ --a ;     printf("b= %d, d = %d" , b,d);     return 0; } 

b= 18, d = 17

the code , it's run

why d&b not equal? can please explain why d=17?

oh right, it's because it's undefined when value of a , c decrement.

d = --c + --c+1;  

if c decremented twice , d calculated, gives

d = 8 + 8 + 1 = 17 

but if c decremented proceed left right, gives

d = 9 + 8 + 1 = 18 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -