Multiple choice

For the statement 'scanf(“%3d %3d %3d”,&a,&b,&c)'; if the input value is 1234 5678 9, then the assignments will be

  1. a=123 b=456 c=789

  2. a=123 b=567 c=9

  3. a=123 b=4 c=567

  4. a=123 b=678 c=9

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The %%3d specifier reads at most 3 digits per number. For input '1234 5678 9': the first %%3d reads '123' (a=123). The next %%3d starts at '4' and reads '4' before hitting the space (b=4). The third %%3d reads '567' (c=567). Space is a whitespace delimiter.