ProgrammingHardGATE CS · TCS NQT
What is printed? Assume unsigned int is 32 bits.
What is printed? Assume unsigned int is 32 bits.
#include <stdio.h>
int main(void) {
int a = -1;
unsigned b = 2;
printf("%u", (unsigned)a * b);
}- A. 4294967294
- B. 8
- C. 4294967295
- D. 2
Correct answer: A. 4294967294
(unsigned)-1 is 4294967295, and multiplying by 2 wraps modulo 2^32 to 4294967294. The signed value -2 is not a valid unsigned result.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { unsigned k = 0; int len = -1; printf("%d", k > len); }
- How many integers in 0..15 are a power of two? Compute with this program. c #include <stdio.h> int main(void) { int c = 0; for (unsigned x…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {3, 1, 2}, swaps = 0; for (int i = 0; i < 3; i++) for (int j = 0; j < 2…
- What is printed? Assume uint32t is 32 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint32t h = 5381; const char s =…
- What is printed? c #include <stdio.h> #include <stdlib.h> struct R { int a, b; }; int cmp(const void p, const void q) { const struct R x =…
- How many values of n in 1..50 have bit 2 set (the value 4)? Compute with this program. c #include <stdio.h> int main(void) { int c = 0…