[LCP]puzzling
Andrew Weaver
Andrew.Weaver at tecnomen.fi
Fri Feb 28 17:32:02 UTC 2003
On Friday, February 28, 2003 10:08 AM, Greg Black [SMTP:gjb at gbch.net] wrote:
> Kurian Abraham Kurian Abraham-A18108 wrote:
>
> | int main()
> | {
> | long a = 13;
> | long b = 197;
> | long c ;
> |
> | c = (b-a)*16.66;
> | printf("\nAmazing = %ld",(b - a)*(16.66));
> | printf("\nC is %ld\n",c);
> | return 0;
> | }
> |
> | pls run this program....and tell me why the answers r different?
>
> They are expected to be different -- the program is wrong.
>
> In the "amazing" line, you tell printf() to expect a long, but
> you pass it a double. You get what you asked for.
>
> Greg
>
Indeed. For further "amusement"look at this...
<snipped>
Kurian, I assume you are new to this C game so please excuse me if I am
wrong. A word of advice - using -Wall and
-Werror options into gcc would have told you exactly what was wrong. I
always use them so that I never get the chance to build a prog with warnings
going off. Compiler warnings are clues that something is perhaps not what
you thought it was and if you get used to ignoring them bad things can (and
do) occur.
Cheers.
More information about the linuxCprogramming
mailing list