Monday, July 15, 2013

A string concatenation puzzle

Happy Canada Day everyone! I'm back from a fabulous week in California and looking forward to taking a break from giving PowerPoint presentations.

Today, to follow up on my recent series on string concatenation, here's a fairly easy little puzzle. I have a perfectly ordinary local variable:

string s = "";

Can you come up with some code that parses as a legal expression such that the statements

s = s + your_expression;

and

s += your_expression;

are both legal but produce completely different results in s? Post your proposals in the comments and I'll give my answer later this week.

QR: Inline image 1