Multiple choice

To accept the first_name, which of the following is the appropriate method?

  1. scanf(“%c”,S.first_name[10]);

  2. scanf(“%s”,S.first_name[10]);

  3. scanf(“%s”,S.first_name);

  4. scanf(“%s”,S->first_name);

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

To read a string into a character array, you pass the base address of the array. S.first_name refers to the array, which decays to a pointer to its first element, making it the correct argument for scanf with the %s format specifier.