A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-22.c
1#include<stdio.h>
2intmain(void){
3doubletotal=0;
4for(inti=0;i<3;i++)
5total+=1/2;
6printf("%.1f\n",total);
7return0;
8}
Conversions
Answer & explanation
Console output
0.0
Why
The expression 1 / 2 is integer division, which is 0, before it is converted to double and added to total. Adding 0.0 three times leaves total at 0.0, even though it is a double. The floating-point accumulator cannot rescue a value that was already truncated to 0 in integer arithmetic.