Re: Difference between Pointers and Reference in C++

pritish's Avatar, Join Date: Sep 2007
Newbie Member
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 shabbir; 11Sep2007 at 18:04.. Reason: Code block
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Because of floating point approximation. Debug it to see that is the exact value of the variable a
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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.