ProgrammingHardTCS NQT · Infosys
What is printed? Assume int is 32 bits.
What is printed? Assume int is 32 bits.
#include <stdio.h>
int main(void) {
int a = -3;
unsigned b = 2;
printf("%u", a * b);
}- A. 4294967288
- B. 4294967290
- C. 6
- D. 4294967289
Correct answer: B. 4294967290
a is converted to unsigned, so a * b is computed modulo 2^32 and gives 2^32 - 6 = 4294967290. The signed value -6 cannot be the result of an unsigned multiplication.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { unsigned a = 7; printf("%u", a / 2 2); }
- What is printed? c #include <stdio.h> int f(int n) { static int memo[10]; if (n < 2) return n; if (memo[n]) return memo[n]; return memo[n]…
- What is printed? c #include <stdio.h> int main(void) { printf("%c", 'a' + ('z' - 'a') / 2); }
- How many trailing one bits does 0x1F3 have? Compute with this program. c #include <stdio.h> int main(void) { unsigned x = 0x1F3; int c =…
- What is printed? c #include <stdio.h> int main(void) { unsigned long long p = 0xFFFFu 0xFFFFu; printf("%llu", p); }
- What is printed? Assume a pointer is 8 bytes and a char array of length 10 is passed to f. c #include <stdio.h> void f(char s[]) {…