by Dinesh Thakur Category: C Programming (Pratical)



# include <stdio.h>

int main ()
        int    i=2;
        printf("%d\n", 8*i/3);  
                /* Note: Integer arithmetic performed on 16/3 => 5 */
        printf("%d\n", 8.0*i);  
/* Error 1: Float value can't be printed with %d (int) specifier,prints 0 instead of 16.000*/
                /* Error 2: Float specifier can't print int value, prints 0.000 instead of 16*/
                /* Error 3: Again wrong specifier, Prints 0.000 instead of 5.000 */
                /* Note: Calculates 16mod3, ie the remainder is 1 */
        /* Correctly prints 5.333 */
        return 0;

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Search Content