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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pravin MoreRank #1,419 · 1.2K reputationPosted Nov 14, 2011, 8:11 PM EST
see "4" + ( 5 + 6) + "10"
this will give output 4128
as parenthisis have highest precedance addition will done before.
Thanks,
Pravin
Pravin MoreRank #1,419 · 1.2K reputationPosted Nov 14, 2011, 7:47 PM EST
output will be 4578.
becoz "4" and "8" are strings, so 5 and 7 gets attached to it by "+" operator.
Thanks,
Pravin.
Akash AhlawatRank #3,915 · 379 reputationPosted Nov 14, 2011, 8:06 PM EST
TulasiRank #2,544 · 549 reputationPosted Nov 14, 2011, 8:26 PM EST
Operator Precedence
is also one reason for this Response.Write("4" + (5 + 7) + "8"); // 4128Murugavel S12 reputationPosted Nov 14, 2011, 8:36 PM EST
Datta KharadRank #2,135 · 668 reputationPosted Nov 14, 2011, 10:20 PM EST
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.
Akash AhlawatRank #3,915 · 379 reputationPosted Nov 15, 2011, 2:35 AM EST
AartiRank #2,383 · 594 reputationPosted Nov 15, 2011, 2:47 AM EST
string str = "4" + 5 + 7 + "8";
output is : 4578
Thanks.
Pravin MoreRank #1,419 · 1.2K reputationPosted Nov 15, 2011, 2:52 AM EST
if you want addition of 5 and 6 to attach string then use below.......
"4" + ( 5 + 6) + "10"
Akash AhlawatRank #3,915 · 379 reputationPosted Nov 17, 2011, 5:50 PM EST