In the below programs , post increment operator is used just after completion of expression evaluation. Now for the first program shouldn't the answer be 40 n then value of a be incremented to 41.N likewise for program 2 answer should be 41 instead of 42?
class IncrementDemo{
public static void main(String [] args){
int a=20;
a= a++ + a++;
System.out.println(a); //Answer given is 41
}
class IncrementDemo{
public static void main(String [] args){
int a=20;
a= a++ + ++a;
System.out.println(a);
}
Answer given is 42 for second program.