Multiple choice technology programming languages

What will be the output ? my $str = 'a\b\n'; print $str;

  1. ab(newline)

  2. a\b\n

  3. a\b(newline)

  4. a\b\n

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In single quotes, backslashes are literal except for \' and \. The string 'a\b\n' contains: 'a', literal backslash, 'b', literal backslash, 'n'. When printed, this shows as 'a\b\n' - the \ is one backslash, and \n is two characters (backslash + n), not a newline character. Option A incorrectly interprets \n as a newline.