1.

What Will Be The Output Of The Following Code Snippet?

Answer»

float NUM1 = 6 / 4;
float num2 = 6 / 4.0;
printf("6/4 == %f or %FN", num1, num2);
OUTPUT will be : 6/4 == 1.000000 or 1. 500000. This is a case of operator promotion. The variable num1 is set to “6/4”. Because, both 3 and 4 are integers. So integer division is performed on them and the result is the integer 0. The variable num2 is set to “6/4.0”. Because 4.0 is a float, the number 6 is converted to a float as well, and the result will be floating value 1.5.

float num1 = 6 / 4;
float num2 = 6 / 4.0;
printf("6/4 == %f or %fn", num1, num2);
Output will be : 6/4 == 1.000000 or 1. 500000. This is a case of operator promotion. The variable num1 is set to “6/4”. Because, both 3 and 4 are integers. So integer division is performed on them and the result is the integer 0. The variable num2 is set to “6/4.0”. Because 4.0 is a float, the number 6 is converted to a float as well, and the result will be floating value 1.5.



Discussion

No Comment Found