what could be the output of below snippet | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what could be the output of below snippet

int x = 5; int y = x-- - 1; System.out.println(x); System.out.println(y);

18th Oct 2016, 6:30 PM
Akshay
Akshay - avatar
3 Answers
+ 1
for better understanding, you have to treat like int x=5; int y=(x--)-1; x having post decrement, so first it's excutes y= x-1; then it's excutes x=x-1; System.out.println(x); //4 System.out.println(y); //4
19th Oct 2016, 3:59 AM
Mani Kanta
Mani Kanta - avatar
0
The otput values of bot are 4. But you can try these snippest on some internet online compilator. for example http://ideone.com/
18th Oct 2016, 6:57 PM
Petr Hatina
Petr Hatina - avatar
0
4
20th Oct 2016, 1:55 PM
Francisco Javier Coenda
Francisco Javier Coenda - avatar