ProgrammingModerateTCS NQT · Wipro
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int x = -8;
printf("%d", x / 2 + x % 3);
}- A. -4
- B. -5
- C. -2
- D. -6
Correct answer: D. -6
Division and remainder truncate toward zero, so -8 / 2 = -4 and -8 % 3 = -2. The sum is -6, and a floor-based remainder would give -2 and a different total.
More C Programming questions
- What is printed? c #include <stdio.h> int calls = 0; int bs(const int a, int lo, int hi, int k) { calls++; if (lo > hi) return -1; int m =…
- What is printed? Assume short is 2 bytes, int is 4 bytes and both use natural alignment. c #include <stdio.h> struct S { char c; short s…
- How many steps does this Collatz loop take to reach 1 starting from 27? c #include <stdio.h> int main(void) { unsigned n = 27; int steps =…
- What is printed? c #include <stdio.h> #include <stdlib.h> int cmp(const void a, const void b) { return (const int )a - (const int )b; }…
- What is printed? Assume unsigned int is 32 bits. c #include <stdio.h> int main(void) { int a = -1; unsigned b = 2; printf("%u"…
- What is printed? c #include <stdio.h> int main(void) { unsigned k = 0; int len = -1; printf("%d", k > len); }