[LCP]puzzling

Greg Black gjb at gbch.net
Fri Feb 28 16:09:02 UTC 2003


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



More information about the linuxCprogramming mailing list