Question 1Medium
What is output for following set of code?
static void Main(string[] args)
{
char A = 'K';
char B = Convert.ToChar(76);
A++;
B++;
Console.WriteLine(A+ " " +B);
Console.ReadLine();
}- M L
- U L
- L M
- A B
Answer: C. L M
Explanation
++ increments the value of character by 1. A and B are given values K and 76, when we use increment operator their values increments by 1, A and B becomes L and M.
Output: L, M.
Step-by-step solution
- Convert.ToChar(76) gives the character L, because 76 is its character code.
- A starts as K and B as L; A++ makes A into L, and B++ makes B into M.
- Console.WriteLine(A + two spaces + B) prints the characters in order: L then M.
- So the answer is option C, L M.
Why the other options are wrong
- A. M L has the letters reversed.
- B. U L is wrong; A becomes L and B becomes M after the increments.
- D. A B is wrong; the ++ operator moves both letters on by one.
Tip: ++ on a char moves it to the next character code; char + string joins the text.