ProgrammingVery hardTCS NQT · Infosys

What is printed? Assume int is 32 bits.

What is printed? Assume int is 32 bits.
#include <stdio.h>
int main(void) {
    unsigned a = 10;
    int b = -3;
    printf("%u", a % b);
}
  1. A. 7
  2. B. 4294967293
  3. C. 3
  4. D. 10

Correct answer: D. 10

In a % b the signed -3 becomes the unsigned value 4294967293, which is far larger than 10, so the remainder is 10 itself. A signed remainder would be 1.

More C Programming questions

Exams that ask this topic