Stump the CFChump – 1

November 28, 2012 by Mike Henke    13 Comments
Posted under: cfchump · ColdFusion

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

13 Comments + Add Comment

  • Marc Esher

    I know! It'll reach out of your monitor, slap you, and tell you to quit writing dumbass code

    :-)

  • Mike Henke

    LOL, a co-worker asked when we'll use something like this. I couldn't really think of an instance except for maybe loops.

  • Ryan Anklam

    Give Marc a gift card. Right now.

  • Dominic Watson

    My gut would say 5 - 5, but I've no idea what CF does here. ++ What Marc said!

  • Brad Wood

    I'm going with 5 - 5 as well since the first increments before using it and the second increments after using it.

  • Brad Wood

    Err, the second decrements I mean.

  • Paul Klinkenberg

    A for sure. Or at least somewhat sure ;-)

  • Paul Klinkenberg

    B! I meant B! Damnit.

  • Michael Zock

    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

  • Mike Henke

    I'll give the previous answer on the next Stump the CFChump question :-) I have about a dozen of these wacky study material.

  • Curt Gratz

    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

  • Dominic Watson

    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?!

  • Garry

    5 -5 ??

    And a final <cfoutput>#myvar#</cfoutput> would read 4.

    I think. I don't tend to use operators like that.

  • Got anything to say? Go ahead and leave a comment!