K

Kanak Sharma • 5.38K Points
Tutor III

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;
}
  • (A) 2
  • (B) 2.5
  • (C) Error
  • (D) Warning

Explanation by: Kanak Sharma
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

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.


Question analytics