Stump the CFChump – 1
I am doing a "Stump the CFChump" series. I recently passed the ColdFusion 9 exam and this is material I learned while studying. I have several CodeSchool gift cards to giveaway so comments who answer correctly I'll email you the discount code. "Stump the Chumps" is from the "Car Talk" so I am spinning that title for ColdFusion. These are questions that stumped me when studying.
- Please try to not google or run the code before answering.
- Must have your correct email address when commenting to receive a CodeSchool giftcard
- Giftcards are available until I run out for correct answers
Stump the CFChump 1
Question
What will display when this code is ran?
<cfset myvar = 4>
<cfoutput>
#++myvar# - #myvar--#
</cfoutput>
Answers
A. 5 – 4
B. 5 – 5
C. 4 – 3
D. 5 – 3




Posted under: 


I know! It'll reach out of your monitor, slap you, and tell you to quit writing dumbass code
:-)
LOL, a co-worker asked when we'll use something like this. I couldn't really think of an instance except for maybe loops.
Give Marc a gift card. Right now.
My gut would say 5 - 5, but I've no idea what CF does here. ++ What Marc said!
I'm going with 5 - 5 as well since the first increments before using it and the second increments after using it.
Err, the second decrements I mean.
A for sure. Or at least somewhat sure ;-)
B! I meant B! Damnit.
Since I'm waiting for several Ant tasks to finish anyway ...
#++myvar# -> increment BEFORE use -> outputs 5
#myvar--# -> decrement AFTER use -> outputs 5
Expected result: B
I'll give the previous answer on the next Stump the CFChump question :-) I have about a dozen of these wacky study material.
I am with Marc Esher, but and the answer is B. unless of course you refactor to #++myvar# - #--myvar#, then it is A, unless of course you refactor to #myvar# - #--myvar#, then the answer is C, unless of course you refactor to #++myvar# - #--myvar-1#, then the answer is D.
WAT!
http://www.youtube.com/watch?v=kXEgk1Hdze0
Wohoo! Never knew CF did pre and post evaluating incrementors - is that what they're called? I remember learning about them just out of school some 13 years ago - never found a use for them myself. Anyone got an example of how you'd use them in web development?!
5 -5 ??
And a final <cfoutput>#myvar#</cfoutput> would read 4.
I think. I don't tend to use operators like that.