 |
BOOK: Beginning Visual C# 2010
 | This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning Visual C# 2010 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 18th, 2010, 10:19 PM
|
|
Registered User
|
|
Join Date: May 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chapter 3 Exercise 4 Solution
in the appendix, the solution to this exercise is:
resultVar += ((var1 * var2) << (var4 / var5));
I could not find an explanation for "<<"
Can someone please explain?
thanks
kb
|
|

May 19th, 2010, 12:33 AM
|
|
Registered User
|
|
Join Date: May 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|

okay...
found the answer (sort of) here:
http://msdn.microsoft.com/en-us/libr...(v=VS.71).aspx
which leaves me more confused than ever as to why that is the answer to Chapter 3 Exercise 4 Solution
|
|

June 22nd, 2010, 10:38 PM
|
|
Registered User
|
|
Join Date: Jun 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Typo
I believe that's just a typo and the correct answer is:
resultVar += (((var1 * var2) + var3) % (var4 / var5));
|
|

July 15th, 2010, 04:22 AM
|
|
Authorized User
|
|
Join Date: Mar 2010
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Yes it is a typo error.
And the correct answer is:
resultVar += ((var1 * var2) + ((var3 % var4) / var5));
*, % and / have the same priority and in that case it is the leftmost operator that operates first.
|
|

July 15th, 2010, 09:20 PM
|
|
Authorized User
|
|
Join Date: Jun 2010
Posts: 27
Thanks: 8
Thanked 0 Times in 0 Posts
|
|
Operator Priority
According to the book:
* has first priority
/ has second and
% has third
page 51 of Beginning Visual C# 2010
So the corrct answer should be:
resultVar += ((var1 * var2) + (var3 % (var4 / var5)));
Tariq
|
|

July 16th, 2010, 05:24 AM
|
|
Authorized User
|
|
Join Date: Mar 2010
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
|
|
No tariq it is not the right answer :
*, / and % have the same priority.
The order displayed in the book or in any website doesn't mean anything.
what I mean is : it is the same whether they write
*, /, %
or
/, *, %
What only matters is the rank (Higher to Lowest)
Try it out on Visual!
|
|

July 16th, 2010, 07:57 AM
|
|
Authorized User
|
|
Join Date: Jun 2010
Posts: 27
Thanks: 8
Thanked 0 Times in 0 Posts
|
|
Thanks
Thanks for the clarification:
What you are saying is that which ever operator comes first out of */and % the calculation will start from there:
Am i right?
For example in this case:
resultVar += (var1 * var2) + (var3 % var4) / var5;
Please correct me if i am on the wrong track.
Tariq
|
|

July 16th, 2010, 08:27 AM
|
|
Authorized User
|
|
Join Date: Mar 2010
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Yes you got it!
That's exactly it
So in your example, the processing will be performed in this order:
*
%
/
+
+=
That is only if you write it without brackets, I mean like that:
resultVar += var1 * var2 + var3 % var4 / var5;
If you use brackets like for example: resultVar += var1 * (var2 + var3) % var4 / var5;
The order will be:
+
*
%
/
+=
Let me know if you understand my explanation (as English is not my first language).
Bon_chan
Last edited by bon_chan; July 16th, 2010 at 08:34 AM..
|
|

July 16th, 2010, 08:13 PM
|
|
Authorized User
|
|
Join Date: Jun 2010
Posts: 27
Thanks: 8
Thanked 0 Times in 0 Posts
|
|
That is perfect:
Thanks for explaining.
Hope to c u in some other discussion.
Regards
Tariq
|
|
 |
|