Ask your own question, for FREE!
Computer Science 15 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!
Latest Questions
Breathless: Spooky witch but cute
5 hours ago 3 Replies 0 Medals
Arriyanalol: help
5 hours ago 10 Replies 2 Medals
Arriyanalol: @tinydinoUwU stop trying to find a argument u blad lil boy
1 day ago 5 Replies 4 Medals
Jaded012023: Please tell me what you all think of this song
8 hours ago 6 Replies 1 Medal
Arriyanalol: bro how
7 hours ago 2 Replies 3 Medals
Arriyanalol: cant wait for the new bluey movie in 2027
1 day ago 12 Replies 2 Medals
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!