1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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,283
    Likes Received:
    364
    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,283
    Likes Received:
    364
    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