Q. What will be the output of the following C code?
Code:
#include <stdio.h>
int main()
{
int x = 20;
x %= 3;
printf("%d",x);
return 0;
}
β
Correct Answer: (A)
2
Explanation: In the above code, the value of x is 20 and then in the next statement, the expression is x %= 3. That will be evaluate as:
x %= 3;
x = x % 3;
x = 20 %3;
x = 2