How does increment work? | SoloLearn: Learn to code for FREE!

+3

How does increment work?

a=2,b=6 ++a+b++ Explain the Operation

8/1/2020 6:16:00 PM

P. Aamir

7 Answers

New Answer

+3

First preincrement will be solve after that post increment Int a=2,b=6,c; c=++a+b++; Here the value of a will be incrementing by 1 becz ++a so the expression will be c=3+6=9 and 9 will be assign in c variable after evaluation of c variable b value will be increase . Hope u understood if u don't know how pre and post inc/dec working u can watch youtube tutorials.

+4

Use the search bar for searching more answers to your question. https://www.sololearn.com/discuss/1777199/?ref=app https://www.sololearn.com/discuss/160327/?ref=app https://www.sololearn.com/discuss/1047413/?ref=app https://www.sololearn.com/discuss/138271/?ref=app

+4

a=2 b=6 print(++a + b++) output : 9 why? Since print(3 + 6) explaination: in ++a, "++" comes before "a" so a is incremented first hence when that print statement is executed we have a becomes 3. in b++, "++" comes after "b" so b is incremented later hence we still have b as 6 when the print statement is executed. (later after the print statement is executed b becomes 7)

+3

ThanksRohit

+2

Can you explain bro Rohit

+2

My example problem how does that workRohit

+2

This was a quiz I gave 9 first it went wrongRohit so I was in confusion and wanted to know the logic