Strings in the D programming language (and in many other languages too) are stored as an array of characters. Sometimes you might forget that you are still working with an array. The following code for example might result in unexpected behaviour.

char[] a = “foo”;
char[] b = “foo”;
a[0] = ‘x’;                    // access violation (Linux)
Stdout(a ~ ” “ ~ b).newline(); // outputs “xoo xoo” (WinXP)

Read more…