(Solved):What is the output for the following code fragment? int var1 = 20; cout –var1; cout var1++; View Answer…

 

Question

What is the output for the following code fragment?

int var1 = 20;
cout << --var1;
cout << var1++;

 

EXPERT ANSWER

The output of the given code fragment will be 19 and 19.

This is so because the first cout statement is used with a pre-decrement operator. This means that the value of the variable, var1, will be first decreased by 1 and then printed, while the decreased value will

Scroll to top