What does the following C statement mean? scanf("%4s", str);

2018

What does the following C statement mean?

scanf("%4s", str);

  1. A.

    Read exactly 4 characters from console

  2. B.

    Read maximum 4 characters from console

  3. C.

    Read a string in multiples of 4

  4. D.

    None of the above

Attempted by 304 students.

Show answer & explanation

Correct answer: B

In scanf, the width specifier %4s reads at most four characters into the string.

Explore the full course: Up Lt Grade Assistant Teacher 2025