Suppose a b and c are part of the same program If a10 b5 and
Suppose, a, b and c are part of the same program. If a=10, b=5 and c=1. Y= (a++) + (--b) + (c--). Z= ++Y. What are the values of Z, a, b and c? (5 points)
a) Z=15, a=11, b=4, c=0.
b)Z=16, a=11, b=4, c=0.
c)Z=15, a= 10, b=4, c=1.
d)Z=16, a=10, b=4, c=1
Solution
a=10, b=5 and c=1
Pre incrementation : ++a
a=10;
cout<<++a; // It prints 11
cout<<a; // It prints 11
Here first of all incrementation of value of a then prints the result.
Post incrementation : a++
a=10;
cout<<a++; // It prints 10
cout<<a; // It prints 11
Here first of all prints the the value of a without incremantation, after print the value it increments the value of a.
Y= (a++) + (--b) + (c--)
Here
Y= 10+4+1=15;
Now the post incrementation and post decrementation values changed as
a=11 and c=0
Z= ++Y; // Since pre incrementation the value of y is incremented so y=16 and assigned to z therefore z=16.
b) Z=16, a=11, b=4, c=0.
Option b is correct choice.
