SUNIL GUTTA

SUNIL GUTTA

  • NA
  • 1k
  • 394k

code snippet ? functionality ??

Jul 25 2013 4:18 PM
Hii

static void Main()
        {
            int i, j = 1, k;
            for (i = 0; i < 5; i++)
            {
                k =j++ + ++j;
                Console.WriteLine(k+"  ");
            }
            Console.ReadKey();
        }

In he above code .. i am getting out put as 4 8 12 16 20 ... well its compiler generated output it cant be wrong but the thing is i am confused .. with the block of code 
             K= j++ + ++J ;
Here acc to pre & post increment operation mechanism say initially j=1 next step j++ it remains 1 only after that ++j it gets 2 so 1+2 should be 3 but y am i getting 4 ..

Hope u got my point TY

Answers (15)