ProgrammingHard

int a = 0, b = 0; char op = 0; int n = sscanf("12 + x", "%d %c %d", &a, &op, &b); printf("%d %c", n, op); What is printed?

  1. A. 2 +
  2. B. 3 +
  3. C. 2 x
  4. D. 1 +

Correct answer: A. 2 +

sscanf converts 12 and then '+', and fails on 'x' for the last %d. It returns the number of successful conversions, 2, and op holds '+'.

More C Programming questions

Exams that ask this topic