scanf returns the number of successfully matched formatting specifiers or EOF if the end of the input was reached before the match (or mismatch) of the first qualifier.
When you press Ctrl + Z, scanf reaches the end of the input and returns EOF (because Ctrl + Z completes the input on Windows). This does not end the for loop because EOF is nonzero, therefore the previous value of t is output (since t not changed by the call). Note that t will not get the EOF value at the end of the input, as you expect: scanf returns EOF as the return value, it does not write it to the pointers that you pass to it.
When you press Ctrl + D, it is treated like any other character. Since it is not numeric, it causes a corresponding failure for the %d specifier and scanf returns 0, which completes the loop.
source share