+ 1
The solution will be a=8, b=10,c=5 how it will be like this
int a=2, b=3, c=4; a += ++c; b += a++;
2 ответов
+ 4
public class Program
{
public static void main(String[] args) {
int a=2, b=3, c=4;
a += ++c;// always first pre increment or pre decrement will solve then post inc/dec
you used pre increment in program so pte increment increase value first then calculate expression
herr
a+=++c c will increase by 1 before c was 4 so it will be 5
a=a+ ++c which is 2+5=7 and it will assign to variable a .
after next step
b += a++;
b=b+a++ it will calculate b=3 and a is 2
so b=3+7 and 10 will assign to b variable but after assign value variable a will increase by 1 becoz u used post increment it will increase after calculate expression so after assigning a will be 8 before calculated a was 7
and
c increase only in first expression
c was 4 so incresed one time so 5
System.out.println(a);
System.out.println(b);
System.out.println(c);
}
}
0
Read about unary operators.