ProgrammingModerateWipro · Capgemini pattern
What is printed?
What is printed?
unsigned char c = 250;
c += 10;
printf("%d", c);- A. 4
- B. 0
- C. 260
- D. 5
Correct answer: A. 4
unsigned char holds 0–255 and unsigned arithmetic wraps modulo 256. 250 + 10 = 260 is computed in int, then stored back as 260 mod 256 = 4. The wrap is well-defined for unsigned types.
More C Programming questions
- What does f(3) print? c void f(int n) { if (n > 0) { f(n - 1); printf("%d ", n); f(n - 1); } }
- What is printed? c char a[] = "hi", b[] = "hi"; if (a == b) printf("same"); else printf("different");
- What is printed? c #define STR(x) #x #define CAT(a, b) a##b int xy = 7; printf("%s %d", STR(x+y), CAT(x, y));
- What is printed? c int x = 2; switch (x) { case 1: printf("A"); case 2: printf("B"); case 3: printf("C"); break; default: printf("D"); }
- What is printed? c int n = 5; while (n-- > 2) printf("%d", n); printf(" %d", n);
- Given int x = 1, y = 2; const int p = &x; int const q = &x; which pair of statements both fail to compile?