What are carriage return, linefeed, and form feed?

后端 未结 12 1433
我寻月下人不归
我寻月下人不归 2020-11-22 14:26

What is the meaning of the following control characters:

  1. Carriage return

  2. Line feed

  3. Form feed

12条回答
  •  粉色の甜心
    2020-11-22 15:09

    \r is carriage return and moves the cursor back like if i will do-

    printf("stackoverflow\rnine")
    ninekoverflow
    

    means it has shifted the cursor to the beginning of "stackoverflow" and overwrites the starting four characters since "nine" is four character long.

    \n is new line character which changes the line and takes the cursor to the beginning of a new line like-

    printf("stackoverflow\nnine")
    stackoverflow
    nine
    

    \f is form feed, its use has become obsolete but it is used for giving indentation like

    printf("stackoverflow\fnine")
    stackoverflow
                 nine
    

    if i will write like-

    printf("stackoverflow\fnine\fgreat")
    stackoverflow
                 nine
                     great
    

提交回复
热议问题