Consider the following C expression ii0 j1j556k a Add paren

Consider the following C++ expression:

i+=i>0 && j>1?(j=5)*5+6:++k;

(a) Add parentheses to this expression until it is fully parenthesized.

(b) What will be the value of this expression if i has the value 1, j has the value 2, and k has the

value 3? (Assume that i, j, and k are all int variables.)

Solution

a)

((i+=(i>0)) && (j>1))?(((j=5)*5)+6):++k;

b)

((i+=(i>0)) && (j>1)) = 2(true) && 1(true) = 1 (true)
So, result will be ((j=5)*5+6) = 5*5+6 = 31

Consider the following C++ expression: i+=i>0 && j>1?(j=5)*5+6:++k; (a) Add parentheses to this expression until it is fully parenthesized. (b) Wh

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site