evaluate the following expressions if the value of the variables are int p,w,k=8 m=11 r=7. (a) p=m+(- -r+k)+3*(m++)*m (b) w=k*(m++3)+(k+--r+r++)
Answers
Answer:
(a) 421
(b)
Explanation:
(a) 11+(6+8)+3*11*12
(b) (m++3)there is an operator missing in between
Answer:
(a.) 421
(b.) 132 (or) program error { see the explanation, why did i get an error }
Explanation:
k=8 m=11 r=7
(a.) p = m+(--r+k) + (3*(m++)*m)
p = 11 + ( 6 + 8 ) + ( 3 * ( 11 ) * 12 )
{ in port-decremented at (--r) the value will be decreased and then posted }
{ in pre-incremented at (m++) the value is posted then incremented so for that value the m will be 11 for next m value it will be 12 }
p = 11 + 14 + ( 396 )
p = 421
(b.) w=k*(m++3)+(k+--r+r++)
{ here the program will say error at m++ because u did not mentioned what operation should be performed after pre incrementing m to 3 so i thought you missed a "+" symbol after pre incrementing m so i took "+" and calculated the answer }
w = 8*( 11 + 3 ) + ( 8 + 6 + 6 )
{ in pre incrementing m the value will be posted first before incrementing}
{ in post decrementing for r the value will be decreased and then printed}
{ in pre incrementing r the value will be posted and then incremented }
w = (8 * 13) + 20
w = 104 + 20
w = 124
-----Hope this will help you understand post and pre incrementing and decrementing. if you like my answer mark brainliest. In future if you any doubts about coding or programming feel free to approach me and ask you doubts or problems, i will try to explain or in most cases solve your problems or doubts :)