locked
What's the difference between these two? RRS feed

  • Question

  • unsigned long mileage = 5UL;
    unsigned long mileage = 5;
    Monday, December 7, 2009 4:01 AM

Answers

All replies

  • There is no practical difference.
    • Proposed as answer by «_Superman_» Monday, December 7, 2009 7:56 AM
    • Marked as answer by Nancy Shao Monday, December 14, 2009 5:39 AM
    Monday, December 7, 2009 4:44 AM
  • But what about:
    float v = 10;
    float f = 10f;

    the book I'm reading says that if you don't append the f with the literal, then it will be a double. but I tested it (initializing v's value to a value higher than a float can hold) and and they are both floats.
    Monday, December 7, 2009 6:46 AM
  • A variable of any type can only hold a maximum value permitted by that type irrespective of how much it is initialized with.
    «_Superman_»
    Microsoft MVP (Visual C++)
    Monday, December 7, 2009 7:56 AM
  • Hi vTurato,

    These two definition are same. The definition float f = 10f, the postfix -f is redundant and unnecessary. It always be used to type casting. For example:

    void f(unsigned int x)
    {
    }
    void f(int x){
    }
    f(3); // f(int x)
    f(3u); // f(unsigned int x)
    For more information, please see this thread with following link:

    http://stackoverflow.com/questions/1273687/why-or-why-not-should-i-use-ul-to-specify-unsigned-long

    Best Regards,
    Nancy
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Nancy Shao Monday, December 14, 2009 5:40 AM
    Wednesday, December 9, 2009 12:15 PM