Thread: Explanation to a problem 2

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    23

    Explanation to a problem 2

    Code:
    #include <stdio.h>
    int main()
    {
            float f=0.0f;
            int i;
    
            for(i=0;i<10;i++)
                    f = f + 0.1f;
    
            if(f == 1.0f)
                    printf("f is 1.0 \n");
            else
                    printf("f is NOT 1.0\n");
    
            return 0;
    }
    My question here is what does the "f" at the end of the values mean? Is it some specifier for a float or just part of the value?

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Is it some specifier for a float
    Correct.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    23
    And why is it used like this?

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Mostly for specificity... The 1.0 could also be interpreted as a double in some cases.

  5. #5
    Registered User
    Join Date
    Aug 2010
    Posts
    231
    1.0 will ever interpreted as double (C standard), therefore there are specifiers l or L for long double and f or F for float.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Explanation to a problem
    By 7h3_0r4c1_3 in forum C Programming
    Replies: 3
    Last Post: 11-10-2011, 05:58 AM
  2. need some explanation
    By abhisheksahni in forum C Programming
    Replies: 5
    Last Post: 11-05-2011, 05:49 PM
  3. explanation please
    By JayCee++ in forum C++ Programming
    Replies: 7
    Last Post: 10-04-2011, 04:17 AM
  4. Explanation pls
    By dpp in forum C++ Programming
    Replies: 6
    Last Post: 09-05-2009, 02:08 PM
  5. Need a bit explanation!!
    By cBegginer in forum C Programming
    Replies: 4
    Last Post: 04-17-2005, 01:36 AM