0

Unable to understand its output. how this operators works? Problem given below. Please help to figure it out

public static void main(String[] args) { int p = 11; int q = 21; int r; int s; r = ++q; s = p++; r++; System.out.println("value of r : " + r); System.out.println("value of s : " + s); } 

Here the output is, value of r : 23 value of s : 11. The r++ increased the value by 1 but when s=p++ its didn't increases its value? Unable to understand why? why here r value increased but not s value?

7
  • 2
    p++ increases the value after the assignment whereas ++q increases the value before assignment. Commented Mar 15, 2018 at 17:22
  • then why r++ increased by 1? Commented Mar 15, 2018 at 17:23
  • @IamSrkfan r=++q; Commented Mar 15, 2018 at 17:23
  • ++ will always increase by 1. Commented Mar 15, 2018 at 17:23
  • then why s value didnt increased by 1? Commented Mar 15, 2018 at 17:24

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.