Answer for my Puzzle

I gave the below question in my last entry. Im giving the answer now.

The answer is, you need to include,


in the if conditional block. I wont give away the reason. Anyone can have a bite at the explanation…..

3 thoughts on “Answer for my Puzzle

  1. That actually doesn’t execute the code in the if block. Instead it just replicates it in the predicate.

    I know very little C++ but a conditional that will execute code in both the if and else blocks on a given predicate seems to be a major bug to me!

    The reason this looks like the answer to this problem is that the && operator executes the first expression (which prints “aa”) and returns a true value. Because the first expression is true, it goes on to the next expression, which evaluates to false. This causes the expression cout<<"aa" in the if block to be skipped and execution continues at the else block, which then prints "dd".

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s