public void A() {
int x;
x = 8;
x *= 4 + 8 / 2;
}
Given the above code, what is the value of "x"?
Answers were Sorted based on User's Feedback
Answer / chandusrit
x*=4+8/2 =====> x=x*(4+8/2)
This is correct and the answer is 64
| Is This Answer Correct ? | 14 Yes | 3 No |
Answer / sasi
64 is the correct answer, i will check it practically
| Is This Answer Correct ? | 7 Yes | 1 No |
Answer / aspdev556
Sorry for the confusion, figured it out.
x = x * 4 + 8 / 2 only multiplies x by 4 not the whole
expression.
| Is This Answer Correct ? | 5 Yes | 1 No |
Answer / aspdev556
64.
Although if you place the same thing like:
x = x * 4 + 8 / 2;
this yields 36 which was my first guess.
How come its producing two different results? Aren't the
assignment statements suppose to get the same result?
| Is This Answer Correct ? | 4 Yes | 2 No |
Answer / vinodh kumar
operator precedence...
* / % + -
x = x * 4 + 8 / 2;
(i) x*(4+(8/2))
(ii) x*(4+4)
(iii) x*8 => Replace x with 8 as per question :P
Ans:64
http://www.blackwasp.co.uk/CSharpOperatorPrecedence.aspx
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / m upendra reddy
i t will foloows the rule of BADMAS
THAT'S why first it caliculate ,like first checks is there
any divisions then caliculate and then multiplictations
x=x*4+8/2;
8/2=4;
then
x=x*4+4;
then x=x*4;==>8*4=32;
now
x=32+4;===>x=36
| Is This Answer Correct ? | 2 Yes | 6 No |
Can You Prevent Your Class From Being Inherited By Another Class?
What are the advantages of using c#?
Is friend a constructor?
What is default constructor in c#?
what is IFormatable
What does async mean in c#?
This is Kishore i am MCA graduate i have percentage less(52%) in my 10th still i completed .NET course any body tell me how to put fake experience with my BSC degree if you do not mind tell me some fake certificates giving consultencies names in Chennai,Bangalore
What is difference between C# and VB.NET?
Explain About stateless and state full web service
Why data types are important in c#?
What is difference between c sharp and c#?
What is int32?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)