Skip to main content
Logo image

Section 3.3 Printing Special Characters

How do you print quotation marks to the screen?

admin.....open in new window

Activity 3.3.

Try printing Today is "Monday"! to the screen. What happens?
What is the correct way to print quotation marks?
Hint.
Be adventurous and try out various ideas! You can’t break anything.
Answer.
  1. Single quotes are printed using \'
  2. Double quotes are printed using \"
Solution.
Within any string (deliminated by double quotes " "), a double quote needs to be “escaped”, that is, preceded by a backslash. Single quotes are actually okay within strings, but it is also okay to escape them. If you’d like to use a single quote within something enclosed by single quotes however, then you need to escape that single quote (but double quotes are okay, surrounded by single quotes).