int x=1; int y=x%x*x/x; | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

int x=1; int y=x%x*x/x;

Please help me how to get the value of y and what will be the correct answer.

5th Aug 2019, 4:29 PM
Khushi Puri
Khushi Puri - avatar
11 Answers
+ 3
So it means the correct answer is 0 Please correct me if I am wrong
5th Aug 2019, 4:50 PM
Khushi Puri
Khushi Puri - avatar
+ 3
But the data type of y is int so please tell why the answer will be 0.0 ?? Thanks for replying
5th Aug 2019, 4:53 PM
Khushi Puri
Khushi Puri - avatar
+ 2
I think the answer should be 0. Please tell me the reason for 0.0 as the correct answer
5th Aug 2019, 4:57 PM
Khushi Puri
Khushi Puri - avatar
+ 2
Thanks
6th Aug 2019, 4:36 PM
Khushi Puri
Khushi Puri - avatar
+ 1
Because %, * and / have the same operator precedence, the operations will be performed from left to right. x%x*x/x =0*x/x =0/x =0
5th Aug 2019, 6:04 PM
Seb TheS
Seb TheS - avatar
+ 1
int x=5 ; int y=x; int y= x++ + x++ - ++x; help me for this operation?
25th Aug 2019, 10:25 PM
Shubham Sase
Shubham Sase - avatar
+ 1
thankx Khushi for helping , I had done operator concept but sometime it make lots of confusion ... but again I will definatly work on this
5th Sep 2019, 5:35 PM
Shubham Sase
Shubham Sase - avatar
0
Hint: y = 1 % 1 * 1 / 1 The remainder of 1/1 multiplied by 1/1
5th Aug 2019, 4:45 PM
Michael
Michael - avatar
0
0.0
5th Aug 2019, 4:51 PM
James
James - avatar
0
the division gives you a float. if it were floor division meaning // it wouldn't be.
5th Aug 2019, 4:58 PM
James
James - avatar
0
Shubham the answer of your question is y=5+6-7=4. Learn about pre and post increment operators.I hope you understand
28th Aug 2019, 3:08 AM
Khushi Puri
Khushi Puri - avatar