C# Programming - Datatypes - Discussion

Discussion Forum : Datatypes - General Questions (Q.No. 8)
8.
What will be the output of the following code snippet when it is executed?
    int x = 1; 
    float y = 1.1f;
    short z = 1;
    Console.WriteLine((float) x + y * z - (x += (short) y));
0.1
1.0
1.1
11
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
18 comments Page 2 of 2.

Gaytri Verma said:   1 decade ago
Its very difficult but help to build the logic.

Sri said:   1 decade ago
Since x=1
y=1.1
z=1
console.write.line(1.0+1.1*1-(x+=1))
1.0+1.1*1-(x=x+1))
1.0+1.1*1-(2)
1.0+1.1-2
2.1-2
0.1

output is 0.1.

Shaila said:   1 decade ago
BODMAS:

(x += (short) y)=[x=x+y]=2 .............. A.

y * z
1.1f*1
1.1f

float(1.1+1) = 2.1 ................ B.

2.1-2=0.1.

Madhuri said:   1 decade ago
Thank you teju.

Teju said:   1 decade ago
Slight changes in sri kantha answer...
Since x=1
y=1.1
z=1
console.write.line(1.0+1.1*1-(x+=1))
1.0+1.1*1-(x=x+1))
1.0+1.1*1-(2)
1.0+1.1-2
2.1-2
0.1
output is 0.1

Ankush said:   1 decade ago
Float is converted to int. I think float should be converted to int.

Srikanth said:   1 decade ago
Since x=1
y=1.1
z=1
console.write.line(1.0+1.1*1-(x+=1))
1.0+1.1*1-(x=x+1+1))
1.0+1.1*1-(2)
1.0+1.1-2
2.1-2
0.1
output is 0.1

Monalisa Arya said:   1 decade ago
Please tell me how it is solved?


Post your comments here:

Your comments will be displayed after verification.