Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the output of this C code?

#include <stdio.h>
    int main()
    {
        printf("sanfoundry\r\nclass\n");
        return 0;
    }

 

  • A.sanfoundryclass
  • B.sanfoundry
    class
  • C.classundry
  • D.sanfoundry

Answer: B

Correct answer: sanfoundry class

Here the carriage return is followed by a newline. The carriage return moves the cursor to the start of the line and the newline moves it down one, so nothing is overwritten and the two words appear on separate lines.

Compare this with the same code using \r alone, which prints classundry because the second word overwrites the first. The pair \r\n is the conventional line ending on some systems, and its combined effect is simply to end the line.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.