Skip to main content

Section 11.2 Practice with Format Specifiers

Check Your Understanding Check Your Understanding

1.

How do you print the sentence She said "yes" to my suggestion. using the printf() command? Feel free to use the window below to try out some commands.

admin.....open in new window

  • printf("She said \"yes\" to my suggestion.");
  • Correct
  • printf("She said "yes" to my suggestion.");
  • Not quite. Try again!
  • printf("She said ""yes"" to my suggestion.");
  • Not quite. Try again!
  • printf("She said 'yes' to my suggestion.");
  • Not quite. Try again!

2.

What happens when you don’t have enough variables to match the number of format specifiers in your format string? For example, what happens when you type:
int age = 34;
printf("I am %d years old and weight %f pounds.", age);
Feel free to quickly write a program to try this out.

admin.....open in new window

  • The compiler will give a warning, but the program will run and print something.
  • Correct
  • The program will compile but crash at runtime.
  • Not quite. Try again!
  • The compiler automatically substitutes the correct value for the missing variable.
  • Not quite. Try again!
  • The compiler will abort with an error message.
  • Not quite. Try again!