Close
Close

why is it showing wrong output?

   neha samala

#include <stdio.h>
float result;   /* Result of the divide */
int main()

{    result = 7.0 / 22.0;
    printf("The result is %d\n", result);   

return (0); 
}


Answers

  •   

    This is because the variable result is of type float and you are using %d to print its value. Use %f instead.


    • even though it is %d it should only print integer value..but it is printing address why?
      - neha samala
    • You have declared the variable result as of type float and printing it as an int. Since there is no automatic conversion of a float to an int, the compiler doesn't understand how to do the conversion. Therefore, it prints a random number (it is not address).
      - Aakhya Singh

Ask Yours
Post Yours
Write your answer