Question & Answer: oid main() { int a,b=5,c=10; a = (b-c) > (c-b) ? b : c; printf(%d,a); } what is the output?/…..

oid main() { int a,b=5,c=10; a = (b-c) > (c-b) ? b : c; printf(%d,a); } what is the output?/

Expert Answer

 

The output of the given code snippet would be 10.

Explanation: the line a = (b-c) > (c-b) ? b : c; uses ternary operator; this means if (b – c) is greater than (c – b) then value of b would be assigned to a otherwise value of c would be assigned to a. Now b=5 and c= 10; so (b – c) is -5 and (c – b) is 5; -5 is not greater than 5 so value of c would be assigned to a. Hence value of ‘a’ would be 10. So print statement would give 10 as output.

Still stressed from student homework?
Get quality assistance from academic writers!