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 1547 students.

Show answer & explanation

Correct answer: B

Explanation: %4s reads at most 4 non-whitespace characters from input and stores them as a C string.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Up Lt Grade Assistant Teacher 2025