How does incremental and decremental operators works ..!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How does incremental and decremental operators works ..!!

For example if a = 0 and b = 1 then what's the answer for ++a && b--

1st Apr 2019, 1:38 PM
Aishwarya Nadimuthu
Aishwarya Nadimuthu - avatar
5 Answers
+ 10
From what I know , they both give the same answer.
1st Apr 2019, 4:58 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 9
Example: a=1 a++ is the same as a=a+1 b=1 b-- is the same as b=b-1 I hope this helps.😊
1st Apr 2019, 2:46 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 2
// post and pre increment is not same // java public class Program { public static void main(String[] args) { int a = 0; System.out.println( a++ + a ); //output 1 a = 0; System.out.println( ++a + a ); //output 2 } } // because // (a++ + a) do (p1+p2) where (p1=0; a=a+1; p2=a) so (0+1) =1 // (++a + a) do (p1+p2) where (a=a+1; p1=a; p2=a) so (1+1) =2
3rd Apr 2019, 2:58 AM
zemiak
+ 1
What's the difference between post and pre increment or decrement....does both gives the same answer?? 💧Alex Tusinean🔥 what is the output of the following code? int a = 8 , b = 9; if((++a>8) && (--b>=9)) print("b"); else print("a");
1st Apr 2019, 4:42 PM
Aishwarya Nadimuthu
Aishwarya Nadimuthu - avatar
+ 1
Post increment ( a++): assigns the value and increments For eg: y=a++; means y=a; and then a=a+1; Similarly pre increment means it increases and assigns the value
22nd Apr 2019, 6:29 AM
Diliban B
Diliban B - avatar