How can a float type variable accept character value and give an output [closed]

C program for finding roots of a quadratic equation

Why this C program returns an output even if I enter a character when its made to accept float type value, it also doesnt ask for the third value then? Also, why this value?

I was expecting an error but the program executed successfully and even returned a value, now I’m confused

  • 2

    Please add your code to the question as text.

    – 

  • 1

    I bet you’re using scanf() without checking to see if it succeeded or not.

    – 

  • 1

    The error message doesn’t match the code. The error message has %c%c%c but the code has %f%f%f

    – 

  • @Shawn %c will always succeed unless it reaches EOF, so checking the return value won’t help.

    – 

  • Using an incorrect format code in scanf() or printf() causes undefined behavior. It doesn’t necessarily cause a visible error.

    – 




Leave a Comment