Output of following expression of C programme | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Output of following expression of C programme

int i=8,j=5; float x=0.005,y=-0.01; char c='c',d='d'; Expression is (3×i-2×j)+(i%2*d-c)

19th Aug 2018, 7:05 AM
Mohit Gupta
Mohit Gupta - avatar
7 Answers
+ 6
Well, I just tested it in Code Playground, the result evaluates to -85, here I try to break the order of operation of the expression, I hope it is clear enough to understand : ) (3 * i - 2 * j) = (3 * 8 - 2 * 5) = (24 - 10) = 14 (i % 2 * d - c) = ((8 % 2) * 'd' - 'c') = (0 * 100 - 99) = -99 14 + (-99) = (14 - 99) = -85 Hth, cmiiw
19th Aug 2018, 9:58 AM
Ipang
+ 4
Have you tried to execute it and get the answer by yourself?... Then, if you don't get it, you can ask others to explain...
19th Aug 2018, 7:22 AM
Ledio Deda
Ledio Deda - avatar
+ 4
it's simple algebraic operations , you just need to know one thing apart from that : whenever you include a character in a arithmetic operation then the number that would be used for it would be it's ASCII code.
19th Aug 2018, 2:46 PM
RZK 022
RZK 022 - avatar
+ 3
my answer was also -85. I just wanted to confirm cause I wasn't sure. thanks a lot .
19th Aug 2018, 4:37 PM
Mohit Gupta
Mohit Gupta - avatar
+ 1
why would I ask a question if I haven't done it myself
19th Aug 2018, 9:16 AM
Mohit Gupta
Mohit Gupta - avatar
+ 1
Please also explain the result
19th Aug 2018, 9:16 AM
Mohit Gupta
Mohit Gupta - avatar
0
the result is 0.1199
19th Aug 2018, 7:24 AM
Emanuele
Emanuele - avatar