Our website uses cookies to enhance your browsing experience.
Accept
to the top
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
What does this code print?

What does this code print?

Sep 11 2012
Author:

I have found a nice code fragment with an error in one project. The PVS-Studio analyzer noticed it. But I didn't believe it at first: I thought the analyzer had been mistaken and considered launching the debugger. Then I looked closer. Oh yes, an error indeed!

I changed the code a bit and sent it to four programmers, acquaintances of mine, via ICQ. I asked them to tell me what that code printed. All four of them gave wrong answers at first.

I suggest that you try to give a correct answer. What does this code print?

cout << (sizeof(char *) == 8) ? "64-bit" : "32-bit";

Of course, the long introduction has alerted the readers, so you have most likely found the right answer.

This code will print one or zero. The expression in parentheses is calculated first. Depending on the compilation mode you get either true or false. The next operation to be executed is the call of an overloaded operator <<. As a result, either number 0 or 1 will appear on the screen.

Then, the object of the ostream type will be implicitly cast to the bool type. And finally the ternary operator '? :' will be executed. But this operation doesn't do anything.

Popular related articles


Comments (0)

Next comments next comments
close comment form