15
Answers

code snippet ? functionality ??

SUNIL GUTTA

SUNIL GUTTA

11y
1.3k
1
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)