Practice mode C#

What does Console.WriteLine(“5” + 3 + 2); print in C#?

Correct answer A. 532

Explanation

The + operator is evaluated left to right. "5" + 3 is string concatenation because one operand is a string, giving "53". Then "53" + 2 gives "532". By contrast, 3 + 2 + "5" first adds the two integers to get 5 and then concatenates, printing 55. Use parentheses, such as "5" + (3 + 2), to force the arithmetic first.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.