+ 3

Why output of this code is 1 not 2 ?

int x = !(1>0) ? 0:1; // here x = 1 x = x++;. // After this statement why x= 1 not 2 ? System.out.print(x); Why post increment is not working ??

29th Jun 2020, 6:43 AM
Randeep Singh
Randeep Singh - avatar
2 ответов
+ 2
The post increment is working. This could explain whats going on: 1 > 0 is true and its value is 1. The ! operator reverses the output of the previous expression shown in parentheses. So it means that the value is now 0. Adding increment to it becomes 1. Thanks for your question and happy coding.
29th Jun 2020, 7:05 AM
James Clark I. Vinarao
James Clark I. Vinarao - avatar
0
Ok thank you 👍
29th Jun 2020, 7:43 AM
Randeep Singh
Randeep Singh - avatar