-2

Can you please explain why the output of Console.WriteLine(beta) is 'A'?According to me it should be 'B'.

public static void Main()
{
    char alpha = 'A';
    char beta = alpha ++;
    char c = alpha++;
    Console.WriteLine(alpha);  //output is C
    Console.WriteLine(beta); //output is A

    Console.ReadLine();
}
Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
jass
  • 1

1 Answers1

2

Because you wrote

char beta = alpha++;

instead of

char beta = ++alpha;

alpha++ returns the value of alpha (1), then increments alpha.

++alpha increments alpha, then returns the new value. (2)

NeedsAnswers
  • 169
  • 5