Confused about getchar() function

后端 未结 6 1788
有刺的猬
有刺的猬 2021-02-07 08:25

I am confused about getchar()\'s role in the following code. I mean I know it\'s helping me see the output window which will only be closed when I press the En

6条回答
  •  南旧
    南旧 (楼主)
    2021-02-07 08:50

    That's because getchar() is a blocking function.

    You should read about blocking functions, which basically make the process wait for something to happen.

    The implementation of this waiting behavior depends on the function, but usually it's a loop that waits for some event to happen.

    For the case of the getchar() function, this probably is implemented as a loop that constantly reads a file (stdin for this case) and checks weather the file is modified. If the file is modified, the loop behaves by doing something else.

提交回复
热议问题