Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

help in increment and decrement operators in c language?? x = 4; y = (++x) + (++x) + (++x); the value of y is 21 . how ?? i am really messed up in pre and post increment and decrement operators ?? pls help

OpenStudy (anonymous):

++x means pre-increment, which happens before anything else. After these three pre-increments, the value of x is 7, because it was a value of 4 that got incremented three times. Then 7 + 7 + 7 = 21. So y = 21. Had it been x++ (i.e., post-increment), then x would still end up 7 (it still gets incremented three times) but the addition would have happened first: 4 + 4 + 4 = 12.

OpenStudy (anonymous):

@bharti795 you should type: y=(++++x)+(++++x)+(++++x); try it, else say me to give you detail PROGRAMME.

OpenStudy (rsmith6559):

When I try this with gcc, I get: warning: operation on ‘x’ may be undefined. This makes sense. In principal, the ( ++x ) would increment x before it's evaluated. The problem comes in with the parentheses. Parentheses are evaluated first, then the rest of the equation is evaluated according to algebraic rules. In principal, the parens would cause the pre-increments to all happen before the additions occur, giving an answer of 21 ( btw, post-incrementing ( x++ ) would accomplish the same thing because the parens would be evaluated first ), but I can't write a program that will get that answer.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!