ProgrammingHardInfosys · Wipro

What is printed?

What is printed?
#include <stdint.h>
#include <stdio.h>
int main(void) {
    uint8_t x = 12;
    uint8_t y = (uint8_t)-x;
    printf("%d", y);
}
  1. A. 4294967284
  2. B. 12
  3. C. 243
  4. D. 244

Correct answer: D. 244

Negation of an unsigned value wraps: -12 converted to uint8_t is 256 - 12 = 244. Taking only the bitwise complement gives 243, which is one less.

More C Programming questions

Exams that ask this topic