How does increment work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How does increment work?

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

1st Aug 2020, 6:16 PM
P. Aamir
P. Aamir - avatar
7 Answers
+ 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.
3rd Aug 2020, 10:41 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 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)
1st Aug 2020, 6:30 PM
Rohit Kh
Rohit Kh - avatar
+ 3
ThanksRohit
1st Aug 2020, 6:33 PM
P. Aamir
P. Aamir - avatar
+ 2
Can you explain bro Rohit
1st Aug 2020, 6:26 PM
P. Aamir
P. Aamir - avatar
+ 2
My example problem how does that workRohit
1st Aug 2020, 6:27 PM
P. Aamir
P. Aamir - avatar
+ 2
This was a quiz I gave 9 first it went wrongRohit so I was in confusion and wanted to know the logic
1st Aug 2020, 6:33 PM
P. Aamir
P. Aamir - avatar