Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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 ajoutée par Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb
Date de publication: 2016/10/19

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
par 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

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?