Did you know…

Consider the following code snippet:

Which one of the following declarations of the variable i will compile without errors and print true when the program runs?

  1. int i = 017;
  2. int i = 15.0f;
  3. int i = 15L;
  4. int i = 15.0;

I will comment out the solution in the next few hours. Stay tunned.

2 thoughts on “Did you know…”

    1. Putting a ‘0’ before a number makes that number an octal number. A decimal equivalent of 017 (in octal) is 15. If you attempt an implicit conversion from float, long, or double types (as given in options 2, 3, and 4 respectively) to an integer, you will a get compiler error.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.