ProgrammingModerateIBM · Deloitte pattern
With 32-bit unsigned int, what is printed?
With 32-bit unsigned int, what is printed?
unsigned int x = 0;
x--;
printf("%u %d", x, x > 0);- A. 4294967295 1
- B. 4294967295 0
- C. 0 0
- D. -1 0
Correct answer: A. 4294967295 1
Unsigned arithmetic wraps modulo 2³², so 0 - 1 = 4294967295. That value is positive, so x > 0 is 1. Unsigned wraparound is defined, unlike signed overflow.
More C Programming questions
- With ASCII and 4-byte int, what is printed? c char c = 'A'; c = c + 32; printf("%c %zu", c, sizeof(c + 1));
- What is printed? c char s[] = "abcdef"; char p = s, q = s + strlen(s) - 1; while (p < q) p++ = q--; printf("%s", s);
- What is printed? c struct A { int a[2]; }; struct B { int p; }; int v = 5; struct A x = {{1, 2}}, y; struct B m = {&v}, n; y = x; n = m…
- With 4-byte int and 8-byte double aligned on 8 bytes, what is sizeof(union U)? c union U { int i; double d; char c[10]; };
- What is printed? c int nextid(void) { static int id = 0; return ++id; } int main(void) { int a = nextid(), b = nextid(), c = nextid()…
- What is printed? c int x = 2; switch (x) { case 1: printf("1"); case 2: printf("2"); case 3: printf("3"); break; default: printf("D"); }