Maha

Maha

  • NA
  • 0
  • 323.6k

Postfix_prefix

Nov 21 2011 7:13 PM
In the following program I entered 10, results are 10, 11, 12 and 11 respectively. Please explain the reason.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace prefix_postfix1
{
class Program
{
static void Main(string[] args)
{
string entry;
int w, x, y, z, n;

Console.Write("Enter an integer ");

entry = Console.ReadLine();
n = Convert.ToInt32(entry);

w = n;
n++;
Console.WriteLine("{0}", w);//output=10

x = n;
++n;
Console.WriteLine("{0}", x);//output=11

y = n;
n--;
Console.WriteLine("{0}", y //output=12

z = n;
--n;
Console.WriteLine("{0}", z);//output=11

Console.ReadKey();
}
}
}


Answers (9)