What is the difference between directly assigning the result of left shift operation to a variable and the left shift assignment operation in C?

Viewed 1698

In the following expression, the result of the left shift operation is assigned to the variable i.

int i;
i = 7 << 32;
printf("i = %d\n",i);

In the following expression, the left shift assignment operation is carried.

int x = 7;
x <<= 32;
printf("x = %d\n",x);

Both the above expressions gave different results. But it's not the same with the following two expressions. Both of them gave the same result. So what could be the reason for the above expressions to return different values?

int a;
a = 1 + 1;
printf("a = %d\n",a);

int b = 1;
b += 1;
printf("b = %d\n",b);
3 Answers
Related