Wrox Programmer Forums
|
BOOK: Ivor Horton's Beginning Visual C++ 2010
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2010 by Ivor Horton; ISBN: 9780470500880
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's 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 September 21st, 2011, 08:35 PM
Registered User
 
Join Date: Sep 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default A 'switch statement' Question (Ex3_06)

The switch statement reads as follows:
Code:
switch(letter*(letter >= 'a' && letter <= 'z'))
My question is, what does the 'letter*' immediately after the switch keyword do? It kind of looks like a pointer but I haven't gotten to that chapter yet.

Thanks,
~hg~

Last edited by haydnguy; September 21st, 2011 at 08:36 PM.. Reason: misstype
 
Old October 12th, 2011, 08:06 AM
Registered User
 
Join Date: Jul 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Smile

in this case, its not for pointer use, its being used as a multiplication symbol, so in the statment

switch(letter * (letter >= 'a' && letter <= 'z'))

the (letter >= 'a' && letter <= 'z') part will result to true(1) or false(0) if you entered a small letter or large letter respectively.

Thus if u enter a small letter, lets say 'b', the switch statement evaluates to (letter * 1) or ('b' * 1) which is 'b' and no case has been written for this, so the default case executes and tells you its a consonant.

If you enter a large letter, say 'D', the switch statement evaluates to (letter * 0) or ('D' * 0) which is 0 and then the case 0 : statements execute and tells you its not a small letter.

My explanations may sound confusing, but thats the best way to explain that example





Similar Threads
Thread Thread Starter Forum Replies Last Post
switch statement crmpicco Javascript How-To 3 March 9th, 2015 10:37 PM
The switch statement lina C++ Programming 1 September 19th, 2011 03:31 PM
Simple Question About Switch Statement AgentSmith ASP.NET 3.5 Basics 1 April 22nd, 2009 11:51 AM
switch statement seymour_glass C# 5 January 24th, 2007 12:08 AM
C# switch statement nalla General .NET 4 December 14th, 2005 05:31 AM





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