in reply to Weird ? behavior of printf / sprintf

"foo $a[%d] bar"
is converted to
"foo " . $a[%d] . " bar"
when the double-quoted string is compiled. This is called "interpolation".

printf("$a[%d]\n", 4);
is therefore the same thing as
printf($a[%d] . "\n", 4);
which is definitely not what you want.

Single-quotes avoid interpolation, and so does escaping the characters ($ and @) that would cause interpolation
printf('$a[%d]'."\n", 4);
printf("\$a[%d]\n", 4);