Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Select output for the following set of code?

   static void Main(string[] args)

        {

            int a =5;

            int b =5;

            int c;

            Console.WriteLine(c = a-- - ++b);

            Console.WriteLine(b);

            Console.ReadLine();

 

        }

 

a) -7,b) -5,c) -6,d),

user-image
Question added by Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb
Date Posted: 2016/10/19
Deleted user
by Deleted user

The above code will return -1 on one line and 6 on the other line.

The expression c = a-- - ++b means we use the value of 'a' before decrementing thus '5' and subtract from b after incrementing by 1 thus '6'. So, c = 5 - 6 = -1

The next line we display the value of b

Muhammad Omar Farooq
by Muhammad Omar Farooq , Software Developer , Werner Machinenbau GmbH

the answer will be printed  -1 in first line and 6 in second line

More Questions Like This