Single-line comments, denoted by "//": Everything from the comment marker to the end of the line is ignored.
- Code: Select all
line of code that does stuff //this is a comment
Multi-line comments, denoted at the beginning by "/* " and at the end by " */". Everything in between is ignored.
- Code: Select all
line of code /*this is a comment
this is also a comment*/ line of code
One thing I like to do is set up comment blocks so that adding or removing one character toggles whether the line is a comment.
Before:
- Code: Select all
/* // */ line of code
After (delete the first apostrophe):
- Code: Select all
///*/ now this is a comment
(whitespace doesn't matter - it's used here for clarity)
The challenge: Design a setup of comment markers around two lines of code such that adding or removing a single character will switch which line is commented. (Exactly one of the two must be commented.)
If this is impossible (prove it!), show how to do it with only two characters.
Now (just in case this is too easy), design a setup for THREE lines of code, such that inserting/removing a character at various positions or something - a change of only one character - switches between which line is activated. Repeat for four, five, etc until you get stuck.
I don't have a solution, not even for the two-line problem. I tried to do it today in programming class and couldn't figure it out.
