Difference between Pointers and Reference in C++

Discussion in 'C++' started by pritish, Sep 11, 2007.

  1. pritish

    pritish New Member

    Joined:
    Sep 4, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    why this behave like this
    Code:
    void main()
    {
          double  a=0.0;
          int i;
          for(i=0;i<=9;i++)
          {
          a+=0.1;
          }
          printf("%lf",a);//--------------->1.000000
          if(a==1.000000)
             printf("yes");
          else
             printf("no");
    }
    ouput--------no
    why output is always no. please explain it.
     
    Last edited by a moderator: Sep 11, 2007
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Because of floating point approximation. Debug it to see that is the exact value of the variable a
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Also Don't jump into an article with your query and place it in the right forum so that all can respond. I have moved your post this time.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice