ProgrammingVery hardCompetitive coding (CP)

What is printed?

What is printed?
#include <stddef.h>
#include <stdio.h>
int main(void) {
    size_t n = 3;
    int k = -2;
    printf("%zu %d", (size_t)(k + n), (n + k > 0));
}
  1. A. 1 1
  2. B. 0 0
  3. C. 2 1
  4. D. 1 0

Correct answer: A. 1 1

k is converted to size_t, so k + n equals (2^64 - 2 + 3) mod 2^64 = 1, and the comparison is also 1 > 0. Treating the sum as signed gives -1.

More C Programming questions

Exams that ask this topic