Unable to understand the output x * = y + 1

I have a problem understanding code output. Any explanation please ...

#include<stdio.h>
void main()
{
     int x=2,y=5;
     x*=y+1;
     printf("%d",x);
}

The output is 12. But according to my understanding, x*=y+1;there is x=x*y+1;, but in accordance with the priority of the operator, x*yit should be evaluated, and then adding 1, therefore, it should be 10 + 1 = 11. But this is 12 - can someone explain please?

+4
source share
9 answers

What happens here is how the order of operations occurs during programming.

Yes, if you had this equation x*y+1, it would be (x * y ) + 1and it would be eleven.

= , , =. .

, x *= y + 1 x = x * ( y + 1 ), 12.
asterisk(*) x x.

+10

x = x * (y + 1);

x = 2 * ( 5 + 1 )
x = 12
+13

: x = x*(y+1);

, 12.

+2

, - :

x*=y+1;  =>  x = x * (y + 1);

BODMAS

+1

x *= y + 1 x = x * (y + 1)

+ , *=.

+1

x*=y; x=x*y; x*=(y+1) , x = x * (y + 1);

+1

c

/ , .

* = + 1;

+ .

x = x * (6)

x = 2 * 6

x = 12;
0

*= - V, .. * .

C- (, ,), y + 1 , *= , x.

0

x = x * (y + 1);

x = 2 * (5 + 1) = 12

, , .

0

All Articles