ProgrammingVery hardProduct company OA

What is printed?

What is printed?
int a = 0, b = 0;
int n = sscanf("12 abc 7", "%d %d", &a, &b);
printf("%d %d %d", n, a, b);
  1. A. 1 12 7
  2. B. 1 12 0
  3. C. 2 12 0
  4. D. 2 12 7

Correct answer: B. 1 12 0

sscanf returns how many items it converted and stores. %d reads 12; the second %d meets "abc", fails, and scanning stops there, so the 7 is never reached and b keeps its 0. The return value 1 is how real code detects such bad input.

More C Programming questions

Exams that ask this topic