Wrox Programmer Forums
|
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
 
Old November 18th, 2010, 01:08 PM
Registered User
 
Join Date: Nov 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Post Chap 03 - pag.47 - Math operators

Hi, I have a doubt about this arguments.

In a book is written about postfix ++ operator:

"Placing it after the operand means that the operand is affected after all other computation of the expression is completed"

and in example:

Code:
int var1, var2 = 5, var3 = 6;
var1 = var2++ * --var3;
and then write:
"Before the expression is avaluated, the -- operator preceding var3 takes effect, changing its value from 6 to 5. You can ignore the ++ operator that follows var2, as it won't take effect until after the calculation is completed"

and in the operator precedence chart (prefix++) have more precedence of (postfix++).

Well, all right but....that logic don't function with this code:

Code:
int a = 5;
int b = a++ * a--;
Follow that logic in b the value after calculus would be 25 but.....no is 30.
Why? In this case (postfix++) don't aspect to solve entire expression but...after a++ they change the value of a and take new value in a-- and THEN calculate product.

Can you explain me all this better? Thanks :)
 
Old November 18th, 2010, 03:10 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

You are absolutely correct!! The book is written very poorly.

The postfix operations take place *IMMEDIATELY* after the value of the expression is fetched. They do *NOT* "take effect until after the calculation is completed". That's just plain wrong!! Good editing should have caught that, but the author should never have written that.
Code:
int a = 5; int b = a++ * a--;
means:
(get the value of a, which is 5)(then increment a to 6)
then prepare to multiply by
(get the value of a, which is 6)(then decrement a to 5)
SO the two "get the value of..." parts there indeed mean you will multiply 6 by 5.
 
Old November 18th, 2010, 03:41 PM
Registered User
 
Join Date: Nov 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

oook
Thank for help me. I wishper that there aren't other logic error some this in the rest of the book

Have a good day!!!
 
Old November 18th, 2010, 04:25 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

You can perhaps see this more clearly happening if you write slightly messier code:
Code:
int a = 5;
int x;
int y;

int b = ( x = a++ ) * ( y = a-- );

and then when you display all 4 variables you will see:
b : 30
a : 5
x : 5
y : 6
 
Old November 18th, 2010, 06:19 PM
Registered User
 
Join Date: Nov 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for help me. :) Now I have understand all. See you next time
 
Old January 17th, 2011, 05:29 AM
Registered User
 
Join Date: Jan 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default aircard for laptop

The decision to choose software testing company is not easy. Enough to know what to look for a software testing and to ensure that provide software testing services that are right for you is very important to the success of software development. This article highlights key factors in making this decision.

aircard for laptop





Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble on page 47 MrClean BOOK: Microsoft SQL Server 2008 Integration Services Problem-Design-Solution 7 September 13th, 2010 05:05 PM
Chap 03 Try It Out -- Error Doug Happ BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 February 11th, 2008 02:31 AM
Math operators nguyendh BOOK: Ivor Horton's Beginning Visual C++ 2005 1 June 25th, 2006 01:35 AM
Outlook '03 automation from Access '03 error Derek_05 Access VBA 2 February 3rd, 2006 06:09 AM
Chap 4--using a combination of operators mixtli BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 June 9th, 2003 04:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.