Thread: what is this type of typecasting called?

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    91

    what is this type of typecasting called?

    in some codes, i see that expressions such as:

    3.14f,(for float)
    2.64l(for long double)

    is used. what is this typecasting method called as?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It is not a typecast; it is just a way of specifying that the literal is of the particular type.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    The reason for it is because by default, 2.31 for example, would be evaluated by the compiler as a double.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    They're called a "suffix"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    30
    anything with a floating point is automatically a double foe the computer. here you say 3.14f, it means.. oh wait, it's not double, it is float. use it as a float!
    also check out this discussion -
    c tricky code

  6. #6
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by guitargod View Post
    anything with a floating point is automatically a double foe the computer. here you say 3.14f, it means.. oh wait, it's not double, it is float. use it as a float!
    also check out this discussion -
    c tricky code
    A little bit of me just died. Thank you.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Typecasting
    By ~Kyo~ in forum C++ Programming
    Replies: 3
    Last Post: 05-10-2011, 05:56 PM
  2. C Typecasting Help
    By 127.0.0.1 in forum C Programming
    Replies: 7
    Last Post: 03-11-2010, 02:26 AM
  3. typecasting
    By eklavya8 in forum C Programming
    Replies: 9
    Last Post: 01-03-2009, 09:02 AM
  4. Replies: 6
    Last Post: 04-21-2006, 08:49 PM
  5. typecasting
    By sreetvert83 in forum C++ Programming
    Replies: 7
    Last Post: 07-22-2005, 01:55 PM