checking for equality between an int and float in C

后端 未结 3 584
感动是毒
感动是毒 2020-12-21 09:55

I came across this piece of code :

int x=3;
float y=3.0;
if(x==y)
  printf(\"x and y are equal\");
else
  printf(\"x and y are not equal\");
3条回答
  •  我在风中等你
    2020-12-21 10:14

    In this question x is an integer value whereas y is a float value... an integer value and a float value cannot be equated...so inorder to check equality we have to typecast either float to integer or vice versa... Hope this may help to clear your concept

提交回复
热议问题