TCS
Company
Programming
Basics
Predict the output of following code:
main()
{
float a=1.1;
double b=1.1;
if(a==b) // datatype is different cant be compared; hence result will be 0
printf(“equal”);
else
printf(“not equal”);
}
1. equal
2. not equal
3. Error
4. equal not equal
Read Solution (Total 10)
-
- Not equal. As mentioned when different datatypes having same value gets compared answer would be 0. If works on boolean
- 6 years agoHelpfull: Yes(7) No(1)
- since, these two are different datatype so it return not equal
- 6 years agoHelpfull: Yes(3) No(1)
- Answer:option 3
because typecasting concepts used here.double datatype cannot be stored on float datatype. - 6 years agoHelpfull: Yes(1) No(1)
- here, float and double is comparing since double is RH side type demotion happens so result becomes 0 and prints not equal
- 6 years agoHelpfull: Yes(0) No(0)
- memory storage is diff so it is NOT EQAL
- 6 years agoHelpfull: Yes(0) No(0)
- answer is not equal becoz it takes values as 1.10000 and so...on
- 6 years agoHelpfull: Yes(0) No(0)
- why does it give answer as "equal" when a value like 1.5 is given instead if 1.1?
- 6 years agoHelpfull: Yes(0) No(0)
- those data types are different .i.e the ans is not qual
- 6 years agoHelpfull: Yes(0) No(0)
- Not equal
Invalid data types
So, else part is executed - 6 years agoHelpfull: Yes(0) No(0)
- not equal datatype is different so can't be compared; hence result will be 0 i.e false
- 5 years agoHelpfull: Yes(0) No(0)
TCS Other Question