- You prompt for input.
- You press 'd' followed by the "Enter" key -> the buffer contains two characters 'd', '/n'.
- getchar reads 'd' from the buffer -> buffer contains single character '/n'.
- Since 'd' is not '0' you reprompt for input, but the buffer already contains '/n' and program doesn't wait for you to input anything.
- getchar reads '/n' from the buffer -> buffer is now empty.
- Since '/n' is not '0' you reprompt for input, program waits for user input.
The double print happens because of the green bits above.