Hii,
I want to know about the output and the logic behind the above query?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pravin MorePosted Nov 15, 2011, 1:11 AM
see "4" + ( 5 + 6) + "10"
this will give output 4128
as parenthisis have highest precedance addition will done before.
Thanks,
Pravin
Akash AhlawatPosted Nov 17, 2011, 10:50 PM
Pravin MorePosted Nov 15, 2011, 7:52 AM
if you want addition of 5 and 6 to attach string then use below.......
"4" + ( 5 + 6) + "10"
AartiPosted Nov 15, 2011, 7:47 AM
string str = "4" + 5 + 7 + "8";
output is : 4578
Thanks.
Akash AhlawatPosted Nov 15, 2011, 7:35 AM
Datta KharadPosted Nov 15, 2011, 3:20 AM
string str = "4" + (5 + 7) + "8";
In above expression, number 4 represent as string bcoz double quotes on 4, it is print as 4.
operator + is used for concatination where two operands are (string and int, string and string) and addition where two operands are (int and int), operator precedence first preference to parenthesis then first it will add 5 and 7 =12 and 8 is string it only concatinated to 12.
string str = "4" + (5 + 7) + "8";
Result :- 4+(5+7)+8
4+12+8
4128.
string str2 = "4" + 5 + 7 + "8";
Result:- 4578.
Murugavel SPosted Nov 15, 2011, 1:36 AM
TulasiPosted Nov 15, 2011, 1:26 AM
Operator Precedence
is also one reason for this Response.Write("4" + (5 + 7) + "8"); // 4128Akash AhlawatPosted Nov 15, 2011, 1:06 AM
Pravin MorePosted Nov 15, 2011, 12:47 AM
output will be 4578.
becoz "4" and "8" are strings, so 5 and 7 gets attached to it by "+" operator.
Thanks,
Pravin.