ProgrammingHardCompetitive coding (CP)
What is printed?
What is printed?
#include <stddef.h>
#include <stdio.h>
int main(void) {
size_t a = 3, b = 5;
printf("%d", (a - b) / 2 > 0);
}- A. 0
- B. 1
- C. 4
- D. 2
Correct answer: B. 1
a - b wraps to SIZE_MAX - 1, and halving that value still leaves a huge number, which is greater than 0. Treating the difference as a signed value would give -1 and a false test, printing 0.
More C Programming questions
- What is printed? c #include <stdio.h> int od(unsigned n); int ev(unsigned n) { return n == 0 ? 1 : od(n - 1); } int od(unsigned n) {…
- A complete binary tree of 7 nodes is stored in an array with children of node i at 2i+1 and 2i+2. The values are v = {5, 3, 8, 1, 4, 9…
- What is printed? c #include <stdio.h> #include <stdlib.h> struct Pair { int a, b; }; int cmp(const void p, const void q) { const struct…
- What is printed? c #include <stdio.h> #include <stdlib.h> #include <string.h> int cmp(const void a, const void b) { const char x = (const…
- How many subarrays of {2, 1, 4, 3, 1, 2, 4} have a sum of exactly 7? Compute with this program. c #include <stdio.h> int main(void) { int…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {1, 3, -1, -3, 5, 3, 6, 7}; int k = 3, dq[8], head = 0, tail = 0, total =…