Explain this | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Explain this

int k=10; k= k++; System.out.printl(k); Output in Java ??

29th Apr 2021, 12:11 PM
Abhishek
Abhishek - avatar
5 Answers
+ 2
Statement `k = k++;` is ineffective, because post increment operator returns the original value of <k>. Just do `k++` without reassigning the operator return value. System.out.println(...); // was System.out.printl(...); P.S. Please tag Java as the relevant language of the question ☝
29th Apr 2021, 12:19 PM
Ipang
+ 1
Please explain easy for me
29th Apr 2021, 12:27 PM
Abhishek
Abhishek - avatar
+ 1
When written in a line, and not repeated, k++ Returns value of <k> unmodified, the modification (increment) takes place after the line is completely processed (after the semicolon - end of statement). The increment effect takes place on the next line. ++k Modifies (increments) value of <k> immediately, and returns the modified (incremented) value without waiting for the line to be completely processed. The increment effect takes place on the same line. * The output is the original value of <k>. You can verify this in Code Playground.
29th Apr 2021, 12:34 PM
Ipang
0
Sir what is the output
29th Apr 2021, 12:32 PM
Abhishek
Abhishek - avatar