ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int h = -17;
unsigned idx = (unsigned)h % 16u;
printf("%u", idx);
}- A. 15
- B. -1
- C. 7
- D. 8
Correct answer: A. 15
Converting -17 to unsigned gives 2^32 - 17, and since 2^32 is divisible by 16, the remainder is 15. A signed remainder would give -1.
More C Programming questions
- What is printed? c #include <stdio.h> #include <stdlib.h> #include <string.h> struct Person { char name[4]; int age; }; int cmp(const void…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {3, 1, 2, 5, 4}, c = 0; for (int i = 0; i < 5; i++) for (int j = i + 1; j…
- What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { uint8t m = 0x0F; for (int i = 0; i < 8; i++) m = (uint8t)((m <<…
- What is printed? c #include <stdio.h> int main(void) { int x = 6; printf("%d", x & -x); }
- What is printed? c #include <stdio.h> int main(void) { const char s = " a bb ccc "; int words = 0, in = 0; for (; s; s++) { if (s == ' ')…
- What is printed? c #include <stdio.h> int ways(int n) { if (n == 0) return 1; if (n < 0) return 0; return ways(n - 1) + ways(n - 3); } int…